diff --git a/scripts/backup b/scripts/backup index 5a69ed2..a97b6a8 100755 --- a/scripts/backup +++ b/scripts/backup @@ -50,6 +50,12 @@ ynh_backup --src_path="/home/yunohost.app/$app" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup --src_path="/etc/logrotate.d/$app" + #================================================= # BACKUP SYSTEMD #================================================= diff --git a/scripts/install b/scripts/install index c6d8199..5f96435 100644 --- a/scripts/install +++ b/scripts/install @@ -66,13 +66,6 @@ ynh_script_progression --message="Finding an available port..." --weight=3 port=$(ynh_find_port --port=8065) ynh_app_setting_set --app=$app --key=port --value=$port -#================================================= -# SET UP INSTALLATION VARIABLES -#================================================= - -data_path="/home/yunohost.app/$app" -logs_path="/var/log/$app" - #================================================= # CREATE A MYSQL DATABASE #================================================= @@ -102,8 +95,32 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" -mkdir -p "$data_path" -mkdir -p "$logs_path" +#================================================= +# CREATE DIRECTORY FOR DATA +#================================================= +ynh_script_progression --message="Creating the data directory..." --weight=1 + +# Create datadir folder +mkdir -p "/home/yunohost.app/$app" +# Define app's data directory +data_path="/home/yunohost.app/$app" +# Give permission to the datadir +chown -R $app: "$data_path" + +#================================================= +# HANDLE LOG FILES AND LOGROTATE +#================================================= +ynh_script_progression --message="Configuring log rotation..." --weight=1 + +# Create log directory +mkdir -p /var/log/$app +#touch /var/log/$app/$app.log +logs_path="/var/log/$app" +touch $install_log +chown $app -R $logs_path + +# Setup logrotate +ynh_use_logrotate #================================================= # EDIT MATTERMOST CONFIG @@ -135,8 +152,6 @@ ynh_store_file_checksum --file="$final_path/config/config.json" #================================================= chown -R $app: $final_path -chown -R $app: $data_path -chown -R $app: $logs_path chmod -R g+w $final_path #================================================= diff --git a/scripts/remove b/scripts/remove index 5d46680..fb1ec22 100755 --- a/scripts/remove +++ b/scripts/remove @@ -68,6 +68,14 @@ ynh_script_progression --message="Removing NGINX web server configuration..." -- # Remove the dedicated NGINX config ynh_remove_nginx_config +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Removing logrotate configuration..." --weight=1 + +# Remove the app-specific logrotate config +ynh_remove_logrotate + #================================================= # REMOVE LOG FILE #================================================= diff --git a/scripts/restore b/scripts/restore index 461f74b..819a728 100644 --- a/scripts/restore +++ b/scripts/restore @@ -13,6 +13,9 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -61,6 +64,7 @@ ynh_restore_file --origin_path="$final_path" #================================================= ynh_restore_file --origin_path="/home/yunohost.app/$app" +chown -R $app: "/home/yunohost.app/$app" #================================================= # RESTORE THE MYSQL DATABASE @@ -85,9 +89,7 @@ ynh_system_user_create --username=$app # Restore permissions on app files chown -R $app: $final_path - -#mkdir -p $data_path -chown -R $app: $data_path +chmod -R g+w $final_path logs_path="/var/log/$app" mkdir -p $logs_path @@ -116,6 +118,12 @@ ynh_script_progression --message="Starting a systemd service..." --weight=2 # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started Mattermost" +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 6fe7293..eb4d378 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -13,6 +13,9 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -33,6 +36,7 @@ language=$(ynh_app_setting_get --app=$app --key=language) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." --weight=1 upgrade_type=$(ynh_check_app_version_changed) @@ -81,7 +85,7 @@ ynh_abort_if_errors #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=3 -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -142,14 +146,35 @@ ynh_add_systemd_config # mv "/var/log/${app}.log" "$logs_path/" # fi +#================================================= +# CREATE DIRECTORY FOR DATA +#================================================= +ynh_script_progression --message="Creating the data directory..." --weight=1 + +# Define app's data directory +data_path="/home/yunohost.app/$app" +# Create datadir folder +mkdir -p $data_path +# Give permission to the datadir +chown -R $app: "$data_path" + #================================================= # RESTORE FILE PERMISSIONS #================================================= chown -R $app: $final_path -chown -R $app: "/home/yunohost.app/$app" +chmod -R g+w $final_path + chown -R $app: "/var/log/$app" +#================================================= +# SETUP LOGROTATE +#================================================= +ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 + +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate + #================================================= # INTEGRATE SERVICE IN YUNOHOST #=================================================