diff --git a/scripts/backup b/scripts/backup index 061d06e..bd7b20f 100755 --- a/scripts/backup +++ b/scripts/backup @@ -22,27 +22,27 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$install_dir" #================================================= -# BACKUP THE NGINX CONFIGURATION +# SYSTEM CONFIGURATION #================================================= +# Backup the nginx configuration ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP LOGROTATE -#================================================= - -ynh_backup --src_path="/var/log/$app" - -#================================================= -# BACKUP SYSTEMD -#================================================= - +# Backup the systemd service unit ynh_backup --src_path="/etc/systemd/system/$app.service" +# Backup the logrotate configuration +ynh_backup --src_path="/etc/logrotate.d/$app" + +#================================================= +# BACKUP THE POSTGRESQL DATABASE +#================================================= +ynh_print_info --message="Backing up the PostgreSQL database..." + +ynh_psql_dump_db --database="$db_name" > db.sql + #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." \ No newline at end of file diff --git a/scripts/change_url b/scripts/change_url index d4c611e..9db32d3 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -46,4 +46,4 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --last +ynh_script_progression --message="Change of URL completed for $app" --last \ No newline at end of file diff --git a/scripts/install b/scripts/install index da84500..14da4f0 100755 --- a/scripts/install +++ b/scripts/install @@ -83,10 +83,13 @@ ynh_add_systemd_config #================================================= ynh_script_progression --message="Configuring logrotate to manage application logfiles" --weight=1 +mkdir -p "/var/log/$app" +touch "/var/log/$app/$app.log" +chown -R "$app:$app" "/var/log/$app" +chmod -R u=rwX,g=rX,o= "/var/log/$app" + # Use logrotate to manage application logfile(s) -ynh_use_logrotate --specific_user=$app -touch /var/log/$app/$app.log -chown -R $app:www-data /var/log/$app/ +ynh_use_logrotate #================================================= # INTEGRATE SERVICE IN YUNOHOST diff --git a/scripts/restore b/scripts/restore index d4f24c7..3bea062 100755 --- a/scripts/restore +++ b/scripts/restore @@ -10,77 +10,49 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=3 +ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_restore_file --origin_path="$install_dir" -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" #================================================= -# SPECIFIC RESTORATION +# RESTORE SYSTEM CONFIGURATIONS #================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=10 +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 -# Define and install dependencies -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version -ynh_use_nodejs - -# Upgrade NPM -ynh_npm install --global npm@6.14.18 - -#================================================= -# RESTORE SYSTEMD -#================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service --quiet -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1 +yunohost service add $app --description="Jellyseer Service" --log="/var/log/$app/$app.log" mkdir -p "/var/log/$app" -chown -R $app: "/var/log/$app" -ynh_restore_file --origin_path="/var/log/$app" +touch "/var/log/$app/$app.log" +chown -R "$app:$app" "/var/log/$app" +chmod -R u=rwX,g=rX,o= "/var/log/$app" + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= -# INTEGRATE SERVICE IN YUNOHOST +# RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 +ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 -yunohost service add $app --log="/var/log/$app/$app.log" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 - -ynh_exec_warn_less ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="" +ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=nginx --action=reload @@ -88,4 +60,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression --message="Restoration completed for $app" --last \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade index 00a2126..878b1ea 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -11,13 +11,6 @@ source /usr/share/yunohost/helpers upgrade_type=$(ynh_check_app_version_changed) -#================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 - -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" - #================================================= # INSTALL DEPENDENCIES #================================================= @@ -28,14 +21,20 @@ ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version # Upgrade NPM ynh_npm install --global npm@6.14.18 +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" + #================================================= # "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...) #================================================= -# BUILD APP +# DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Building app... This may take quiete some time" --weight=30 - -ynh_secure_remove $install_dir/terraforming-mars cd $install_dir ynh_exec_warn_less git clone https://github.com/terraforming-mars/terraforming-mars.git @@ -57,6 +56,19 @@ chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:$app "$install_dir" +#================================================= +# REAPPLY SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +ynh_add_nginx_config + +ynh_add_systemd_config + +yunohost service add $app --description="Jellyseer Service" --log="/var/log/$app/$app.log" + +ynh_use_logrotate --non-append + #================================================= # RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) #================================================= @@ -66,45 +78,18 @@ ynh_script_progression --message="Updating a configuration file..." --weight=1 ynh_add_config --template="../conf/.env" --destination="$install_dir/.env" -chmod 600 "$install_dir/.env" +chmod 400 "$install_dir/.env" chown $app:$app "$install_dir/.env" -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Configuring a systemd service..." - -# Create a dedicated systemd config -ynh_add_systemd_config - -#================================================= -# GENERIC FINALIZATION -#================================================= -# LOGROTATE -#================================================= -ynh_script_progression --message="Configuring logrotate to manage application logfiles" --weight=1 - -# Use logrotate to manage application logfile(s) -ynh_use_logrotate --specific_user=$app -touch /var/log/$app/$app.log -chown -R $app:www-data /var/log/$app/ - -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - -yunohost service add $app --log="/var/log/$app/$app.log" - #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_exec_warn_less ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="" +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression --message="Upgrade of $app completed" --last \ No newline at end of file