aboutsummaryrefslogtreecommitdiff
path: root/scripts/restore
diff options
context:
space:
mode:
authoryalh76 <yalh@yahoo.com>2019-05-12 20:32:49 +0200
committerGitHub <noreply@github.com>2019-05-12 20:32:49 +0200
commitf6bf3f01c9bbe6862cb8360e05245672e33963e5 (patch)
tree0cf3ea06df3f1b5f6206d51518f805a481417117 /scripts/restore
parent0e6fcf1700e12399fea0bf3ba0c91a71f0bec9cc (diff)
parentc857d70f73587852cacc608a4e140b5b6b2b9e87 (diff)
downloadmastodon_ynh-f6bf3f01c9bbe6862cb8360e05245672e33963e5.tar.gz
mastodon_ynh-f6bf3f01c9bbe6862cb8360e05245672e33963e5.tar.bz2
mastodon_ynh-f6bf3f01c9bbe6862cb8360e05245672e33963e5.zip
Merge pull request #140 from YunoHost-Apps/example_ynh
Example ynh
Diffstat (limited to 'scripts/restore')
-rw-r--r--scripts/restore82
1 files changed, 42 insertions, 40 deletions
diff --git a/scripts/restore b/scripts/restore
index a31fa29..e85815c 100644
--- a/scripts/restore
+++ b/scripts/restore
@@ -10,7 +10,6 @@
source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_install_ruby
source ../settings/scripts/ynh_add_secure_repos__3
-source ../settings/scripts/ynh_systemd_action
source /usr/share/yunohost/helpers
#=================================================
@@ -26,51 +25,55 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
-ynh_print_info "Loading settings..."
+ynh_script_progression --message="Loading settings..." --weight=2
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
+db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
-ynh_print_info "Validating restoration parameters..."
+ynh_script_progression --message="Validating restoration parameters..." --weight=2
-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..." --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..." --weight=105
-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..." --weight=5
# 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..." --weight=4
# Restore permissions on app files
chown -R $app: $final_path
@@ -80,7 +83,7 @@ chown -R $app: $final_path
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
-ynh_print_info "Reinstalling dependencies..."
+ynh_script_progression --message="Reinstalling dependencies..." --weight=63
# Import debian archive pubkey, need on ARM arch
arch=$(uname -m)
@@ -96,13 +99,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..." --weight=393
ynh_install_ruby --ruby_version=2.6.1
/opt/rbenv/versions/2.6.1/bin/gem update --system
@@ -110,60 +114,58 @@ ynh_install_ruby --ruby_version=2.6.1
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
-ynh_print_info "Restoring the PostgreSQL database..."
-
-db_pwd=$(ynh_app_setting_get "$app" db_pwd)
+ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=18
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_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
+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..." --weight=3
-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..." --weight=3
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..." --weight=41
-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..." --weight=2
-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..." --weight=2
-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" --last