diff options
| author | yalh76 <yalh@yahoo.com> | 2019-05-10 16:34:57 +0200 |
|---|---|---|
| committer | yalh76 <yalh@yahoo.com> | 2019-05-10 16:34:57 +0200 |
| commit | ae5845526a964e0ab8161acf74b060f733191c5e (patch) | |
| tree | a035fb13e9d1b039593a4ea5ff1749ac8eef170f /scripts/restore | |
| parent | 629b59bc5357860b33417fe69eceb413185b68da (diff) | |
| download | mastodon_ynh-ae5845526a964e0ab8161acf74b060f733191c5e.tar.gz mastodon_ynh-ae5845526a964e0ab8161acf74b060f733191c5e.tar.bz2 mastodon_ynh-ae5845526a964e0ab8161acf74b060f733191c5e.zip | |
Apply example_ynh
Diffstat (limited to 'scripts/restore')
| -rw-r--r-- | scripts/restore | 79 |
1 files changed, 42 insertions, 37 deletions
diff --git a/scripts/restore b/scripts/restore index 97b77cf..0b5bde2 100644 --- a/scripts/restore +++ b/scripts/restore @@ -25,51 +25,54 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading settings..." +ynh_script_progression --message="Loading settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -final_path=$(ynh_app_setting_get $app final_path) -db_name=$(ynh_app_setting_get $app db_name) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$app #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_print_info "Validating restoration parameters..." +ynh_script_progression --message="Validating restoration parameters..." --time --weight=1 -ynh_webpath_available $domain $path_url \ - || ynh_die "Path not available: ${domain}${path_url}" +ynh_webpath_available --domain=$domain --path_url=$path_url \ + || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ -|| ynh_die "There is already a directory: $final_path " + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring nginx configuration..." --time --weight=1 -ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_print_info "Restoring the app main directory..." +ynh_script_progression --message="Restoring the app main directory..." --time --weight=1 -ynh_restore_file "$final_path" +ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_print_info "Recreating the dedicated system user..." +ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create $app $final_path +ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # RESTORE USER RIGHTS #================================================= +ynh_script_progression --message="Restoring users rights..." --time --weight=1 # Restore permissions on app files chown -R $app: $final_path @@ -79,7 +82,7 @@ chown -R $app: $final_path #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_print_info "Reinstalling dependencies..." +ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1 # Import debian archive pubkey, need on ARM arch arch=$(uname -m) @@ -95,13 +98,14 @@ fi ynh_install_extra_repo --repo="deb https://dl.yarnpkg.com/debian/ stable main" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" --append # install nodejs -ynh_install_nodejs 8 +ynh_install_nodejs --nodejs_version="8" ynh_install_app_dependencies $pkg_dependencies #================================================= # INSTALLING RUBY AND BUNDLER #================================================= +ynh_script_progression --message="Installing Ruby..." --time --weight=1 ynh_install_ruby --ruby_version=2.6.0 /opt/rbenv/versions/2.6.0/bin/gem update --system @@ -109,60 +113,61 @@ ynh_install_ruby --ruby_version=2.6.0 #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_print_info "Restoring the PostgreSQL database..." +ynh_script_progression --message="Restoring the PostgreSQL database..." --time --weight=1 db_pwd=$(ynh_app_setting_get "$app" db_pwd) ynh_psql_test_if_first_run -ynh_psql_create_user "$app" "$db_pwd" -ynh_psql_execute_as_root \ -"CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;" -ynh_psql_execute_file_as_root ./db.sql "$db_name" +ynh_psql_create_user "$db_user" "$db_pwd" +ynh_psql_execute_as_root --sql="CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $db_user;" +ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" #================================================= # RESTORE SYSTEMD #================================================= -ynh_print_info "Restoring the systemd configuration..." +ynh_script_progression --message="Restoring the systemd configuration..." --time --weight=1 -ynh_restore_file "/etc/systemd/system/$app-web.service" -ynh_restore_file "/etc/systemd/system/$app-sidekiq.service" -ynh_restore_file "/etc/systemd/system/$app-streaming.service" +ynh_restore_file --origin_path="/etc/systemd/system/$app-web.service" +ynh_restore_file --origin_path="/etc/systemd/system/$app-sidekiq.service" +ynh_restore_file --origin_path="/etc/systemd/system/$app-streaming.service" systemctl enable "$app-web" "$app-sidekiq" "$app-streaming" #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= +ynh_script_progression --message="Advertising service in admin panel..." --time --weight=1 yunohost service add $app-web yunohost service add $app-sidekiq yunohost service add $app-streaming #================================================= -# RESTORE THE CRON FILE +# START SYSTEMD SERVICE #================================================= +ynh_script_progression --message="Starting a systemd service..." --time --weight=1 -ynh_restore_file "/etc/cron.d/$app" +ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on tcp" +ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Starting processing" +ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening" #================================================= -# GENERIC FINALIZATION -#================================================= -# START MASTODON SERVICES +# RESTORE THE CRON FILE #================================================= -ynh_print_info "Starting Mastodon services..." +ynh_script_progression --message="Restoring a cron job for removing cache..." --time --weight=1 -ynh_systemd_action --action=start --service_name=${app}-web --line_match="Listening on tcp" --log_path=systemd -ynh_systemd_action --action=start --service_name=${app}-sidekiq --line_match="Starting processing" --log_path=systemd -ynh_systemd_action --action=start --service_name=${app}-streaming --line_match="Worker 1 now listening" --log_path=systemd +ynh_restore_file --origin_path="/etc/cron.d/$app" #================================================= +# GENERIC FINALIZATION +#================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Restoration completed for $app" +ynh_script_progression --message="Restoration completed for $app" --time --last |
