diff options
Diffstat (limited to 'scripts/restore')
| -rw-r--r-- | scripts/restore | 85 |
1 files changed, 74 insertions, 11 deletions
diff --git a/scripts/restore b/scripts/restore index f1c80ee..946a62b 100644 --- a/scripts/restore +++ b/scripts/restore @@ -4,12 +4,19 @@ # Exit on command errors and treat unset variables as an error set -eu -# The parameter $app is the id of the app instance ex: ynhexample__2 -app=$YNH_APP_INSTANCE_NAME - +if [ ! -e .fonctions ]; then + # Get file fonction if not been to the current directory + sudo cp ../settings/scripts/.fonctions ./.fonctions + sudo chmod a+rx .fonctions +fi +# Loads the generic functions usually used in the script +source .fonctions # Source app helpers source /usr/share/yunohost/helpers +# The parameter $app is the id of the app instance ex: ynhexample__2 +app=$YNH_APP_INSTANCE_NAME + # Get old parameter of the app domain=$(ynh_app_setting_get $app domain) path=$(ynh_app_setting_get $app path) @@ -17,7 +24,7 @@ is_public=$(ynh_app_setting_get $app is_public) # Check domain/path availability sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path}" + || ynh_die "Path not available: ${domain}${path}" # Check $final_path final_path="/opt/${app}" @@ -30,7 +37,7 @@ nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" if [ -f $nginx_conf ]; then ynh_die "The NGINX configuration already exists at '${nginx_conf}'. You should safely delete it before restoring this app." - +fi # Check configuration files php-fpm crontab_conf="/etc/cron.d/${app}" if [ -f $crontab_conf ]; then @@ -55,17 +62,38 @@ if [ -f "${streaming_systemd}" ]; then You should safely delete it before restoring this app." fi +# Create user unix +sudo adduser $app --home /opt/$app --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password --disabled-login + # Restore sources & data -sudo cp -a ./sources "$final_path" +sudo cp -a ./sources/. "$final_path" # Set permissions sudo chown -R $app: "$final_path" -# Restore db +# Debug +sudo ls -alh "$final_path" + +# Change directory for create user & database postgresql + +# Set UTF8 encoding by default +sudo su -c "psql" postgres <<< \ + "update pg_database set datistemplate='false' where datname='template1';" +sudo su -c "psql" postgres <<< \ + "drop database template1;" +sudo su -c "psql" postgres <<< \ + "create database template1 encoding='UTF8' template template0;" +sudo su -c "psql" postgres <<< \ + "update pg_database set datistemplate='true' where datname='template1';" + +# Create user for db postgresql ynh_psql_create_db_without_password "$app" -sudo su - postgres <<COMMANDS -pg_dump mastodon_production < ./mastodon_db.sql -COMMANDS + +# Setup database +sudo su - $app <<SCOMMANDS +cd ~/live +RAILS_ENV=production bin/bundle exec rails db:setup +SCOMMANDS # Restore Mastodon sudo su - $app <<RCOMMANDS @@ -74,10 +102,45 @@ RAILS_ENV=production bin/bundle exec rails db:migrate RAILS_ENV=production bin/bundle exec rails assets:precompile RCOMMANDS +# copy database +sudo cp $YNH_APP_BACKUP_DIR/mastodon_db.sql $final_path +sudo chmod a+r $final_path/mastodon_db.sql + +# Restore database +sudo su - $app <<RECOMMANDS +dropdb mastodon_production +createdb mastodon_production +psql mastodon_production < $final_path/mastodon_db.sql +RECOMMANDS + +# Remove dump +sudo rm $final_path/mastodon_db.sql + +# Create symlink for ruby +sudo ln -s /opt/mastodon/.rbenv/versions/2.4.1/bin/ruby /usr/bin/ruby || true + # Restore nginx configuration files sudo cp -a ./nginx.conf "$nginx_conf" # Restore crontab sudo cp -a ./cron.conf "$crontab_conf" +sudo cp ./systemd_web.service /etc/systemd/system/mastodon-web.service +sudo chown root: /etc/systemd/system/mastodon-web.service +sudo cp ./systemd_sidekiq.service /etc/systemd/system/mastodon-sidekiq.service +sudo chown root: /etc/systemd/system/mastodon-sidekiq.service +sudo cp ./systemd_streaming.service /etc/systemd/system/mastodon-streaming.service +sudo chown root: /etc/systemd/system/mastodon-streaming.service + +sudo systemctl daemon-reload +sudo systemctl enable /etc/systemd/system/mastodon-*.service +sudo systemctl start mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service +# debug +sudo systemctl status mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service + +# Add service YunoHost +sudo yunohost service add mastodon-web +sudo yunohost service add mastodon-sidekiq +sudo yunohost service add mastodon-streaming + # Reload services -sudo systemctl reload nginx
\ No newline at end of file +sudo systemctl reload nginx |
