From 77a7af95e94d037c980dfa75f3b837d9ac91a8df Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sun, 3 Oct 2021 13:54:44 +0200 Subject: [PATCH] Add logrotate --- check_process | 6 +----- conf/app.src | 1 - manifest.json | 4 ++-- scripts/backup | 6 ++++++ scripts/install | 39 +++++++++++++++++++------------------ scripts/remove | 16 ++++++++++++++++ scripts/restore | 19 ++++++++++-------- scripts/upgrade | 51 +++++++++++++++++++++++++------------------------ 8 files changed, 82 insertions(+), 60 deletions(-) diff --git a/check_process b/check_process index 70c1485..f4e3327 100644 --- a/check_process +++ b/check_process @@ -11,10 +11,8 @@ setup_private=1 setup_public=1 upgrade=1 - # 4.3.3 - upgrade=1 from_commit=198004df76b0b3ef22a6dfe1b9a2738af62f0786 # 4.9.4 - upgrade=1 from_commit=7a150ab29ee969f72dd7846539ae12ac1975165b + upgrade=1 from_commit=7a150ab29ee969f72dd7846539ae12ac1975165b backup_restore=1 multi_instance=1 change_url=0 @@ -22,7 +20,5 @@ Email= Notification=none ;;; Upgrade options - ; commit=198004df76b0b3ef22a6dfe1b9a2738af62f0786 - name=4.3.3 ; commit=7a150ab29ee969f72dd7846539ae12ac1975165b name=4.9.4 diff --git a/conf/app.src b/conf/app.src index 01ef1dc..17ecce9 100644 --- a/conf/app.src +++ b/conf/app.src @@ -3,4 +3,3 @@ SOURCE_SUM=DE7041DA31362BB8DF1043864A94026D6B692EBCEF8FEBD886F635BEF8E3DA84 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip SOURCE_IN_SUBDIR=false -SOURCE_FILENAME= diff --git a/manifest.json b/manifest.json index 131821b..503eea8 100644 --- a/manifest.json +++ b/manifest.json @@ -3,8 +3,8 @@ "id": "ghost", "packaging_format": 1, "description": { - "en": "Just a blogging platform", - "fr": "Plateforme de blogging" + "en": "Publishing, memberships, subscriptions and newsletters platform", + "fr": "Plateforme d'édition, d'adhésions, d'abonnements et de newsletters" }, "version": "4.16.0~ynh1", "url": "https://ghost.org/", diff --git a/scripts/backup b/scripts/backup index 63ac358..dceee37 100755 --- a/scripts/backup +++ b/scripts/backup @@ -50,6 +50,12 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SPECIFIC BACKUP +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup --src_path="/etc/logrotate.d/$app" + #================================================= # BACKUP SYSTEMD #================================================= diff --git a/scripts/install b/scripts/install index 6862964..964ff73 100644 --- a/scripts/install +++ b/scripts/install @@ -72,6 +72,14 @@ ynh_install_nodejs --nodejs_version=$NODEJS_VERSION # Install Yarn ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # CREATE A MYSQL DATABASE #================================================= @@ -81,15 +89,6 @@ db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -104,6 +103,10 @@ ynh_setup_source --dest_dir="$final_path" mkdir -p $final_path/core/client/Admin ynh_setup_source --dest_dir="$final_path/core/client/Admin" --source_id="admin" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -120,14 +123,15 @@ ynh_add_nginx_config ynh_script_progression --message="Modifying a config file..." ynh_add_config --template="../conf/config.production.json" --destination="$final_path/config.production.json" +chmod 400 "$final_path/config.production.json" +chown $app:$app "$final_path/config.production.json" #============================================== # BUILD GHOST #============================================== ynh_script_progression --message="Building $app... (this will take some time and resources!)" -pushd "$final_path" || ynh_die - +pushd "$final_path" ynh_use_nodejs ynh_exec_warn_less yarn install --non-interactive --silent ynh_exec_warn_less yarn global add knex-migrator @@ -135,8 +139,7 @@ pushd "$final_path" || ynh_die ynh_exec_warn_less yarn global add grunt-cli ember-cli ynh_exec_warn_less NODE_ENV=production grunt symlink ynh_exec_warn_less NODE_ENV=production grunt init --force - -popd || ynh_die +popd #================================================= # SETUP SYSTEMD @@ -147,14 +150,12 @@ ynh_script_progression --message="Configuring a systemd service..." ynh_add_systemd_config #================================================= -# GENERIC FINALIZATION +# SETUP LOGROTATE #================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Securing files and directories..." +ynh_script_progression --message="Configuring log rotation..." -# Set permissions to app files -chown -R $app: $final_path +# Use logrotate to manage application logfile(s) +ynh_use_logrotate #================================================= # INTEGRATE SERVICE IN YUNOHOST diff --git a/scripts/remove b/scripts/remove index 063bd18..36494ad 100644 --- a/scripts/remove +++ b/scripts/remove @@ -43,6 +43,14 @@ ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Removing logrotate configuration..." + +# Remove the app-specific logrotate config +ynh_remove_logrotate + #================================================= # REMOVE THE MYSQL DATABASE #================================================= @@ -77,6 +85,14 @@ ynh_script_progression --message="Removing NGINX web server configuration..." # Remove the dedicated nginx config ynh_remove_nginx_config +#================================================= +# REMOVE VARIOUS FILES +#================================================= +ynh_script_progression --message="Removing log files..." + +# Remove the log files +ynh_secure_remove --file="/var/log/$app" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 405d5e9..36fcda4 100755 --- a/scripts/restore +++ b/scripts/restore @@ -57,7 +57,7 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_script_progression --message="Recreating the dedicated system user..." # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE THE APP MAIN DIR @@ -66,13 +66,9 @@ ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$final_path" -#================================================= -# RESTORE USER RIGHTS -#================================================= -ynh_script_progression --message="Restoring user rights..." - -# Restore permissions on app files -chown -R $app: $final_path +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # SPECIFIC RESTORATION @@ -107,6 +103,13 @@ ynh_script_progression --message="Restoring the systemd configuration..." 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..." + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index a2af1bc..1f54707 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -27,10 +27,24 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) #================================================= # CHECK VERSION #================================================= -ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # restore it if the upgrade fails + ynh_clean_check_starting + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -49,21 +63,6 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # restore it if the upgrade fails - ynh_clean_check_starting - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -79,7 +78,7 @@ ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$ ynh_script_progression --message="Making sure dedicated system user exists..." # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -147,23 +146,25 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st ynh_script_progression --message="Modifying a config file..." ynh_add_config --template="../conf/config.production.json" --destination="$final_path/config.production.json" +chmod 400 "$final_path/config.production.json" +chown $app:$app "$final_path/config.production.json" #============================================== # BUILD GHOST #============================================== + if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Building $app... (this will take some time and resources!)" - pushd "$final_path" || ynh_die + pushd "$final_path" ynh_exec_warn_less yarn install ynh_exec_warn_less yarn global add knex-migrator ynh_exec_warn_less NODE_ENV=production knex-migrator init ynh_exec_warn_less yarn global add grunt ynh_exec_warn_less NODE_ENV=production grunt symlink ynh_exec_warn_less NODE_ENV=production grunt init --force - - popd || ynh_die + popd fi #================================================= @@ -173,16 +174,16 @@ ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config ynh_add_systemd_config - + #================================================= # GENERIC FINALIZATION #================================================= -# SECURE FILES AND DIRECTORIES +# SETUP LOGROTATE #================================================= -ynh_script_progression --message="Securing files and directories..." +ynh_script_progression --message="Upgrading logrotate configuration..." -# Set permissions on app files -chown -R $app: $final_path +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append #================================================= # INTEGRATE SERVICE IN YUNOHOST