From 7b0573e657520e5a2e1c5ed55e7f2ffb79dfbdb3 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 8 Feb 2022 01:41:44 +0100 Subject: [PATCH] Fix logs and .cache too big --- conf/production.yaml | 2 +- scripts/install | 16 ++++++++++------ scripts/remove | 10 ++++++++++ scripts/restore | 9 ++++----- scripts/upgrade | 16 +++++++++++----- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/conf/production.yaml b/conf/production.yaml index 275c91f..3910e55 100644 --- a/conf/production.yaml +++ b/conf/production.yaml @@ -88,7 +88,7 @@ storage: videos: '__DATADIR__/videos/' streaming_playlists: '__DATADIR__/streaming-playlists/' redundancy: '__DATADIR__/redundancy/' - logs: '__DATADIR__/logs/' + logs: '/var/log/__APP__/' previews: '__DATADIR__/previews/' thumbnails: '__DATADIR__/thumbnails/' torrents: '__DATADIR__/torrents/' diff --git a/scripts/install b/scripts/install index 65885a7..c0e23e8 100644 --- a/scripts/install +++ b/scripts/install @@ -55,7 +55,6 @@ ynh_script_progression --message="Storing installation settings..." ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=admin --value=$admin -ynh_app_setting_set --app=$app --key=datadir --value=$datadir #================================================= # STANDARD MODIFICATIONS @@ -163,11 +162,13 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Creating a data directory..." +ynh_app_setting_set --app=$app --key=datadir --value=$datadir + mkdir -p $datadir -chmod 750 "$datadir/.." -chmod -R o-rwx "$datadir/.." -chown -R $app:www-data "$datadir/.." +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:www-data "$datadir" #================================================= # BUILD YARN DEPENDENCIES @@ -177,6 +178,7 @@ ynh_script_progression --message="Building Yarn dependencies..." pushd "$final_path" ynh_use_nodejs ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --production --pure-lockfile + ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn cache clean popd #================================================= @@ -207,6 +209,8 @@ ynh_add_systemd_config #================================================= ynh_script_progression --message="Starting a systemd service..." +mkdir -p "/var/log/$app" +chown -R $app:$app "/var/log/$app" # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP server listening on localhost" @@ -253,14 +257,14 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" ynh_script_progression --message="Configuring log rotation..." # Use logrotate to manage application logfile(s) -ynh_use_logrotate --logfile="$datadir/logs/peertube.log" +ynh_use_logrotate #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description="$app daemon for Peertube" --log="$datadir/logs/peertube.log" --needs_exposed_ports $rtmp_port +yunohost service add $app --description="$app daemon for Peertube" --log="/var/log/$app/$app.log" --needs_exposed_ports $rtmp_port #================================================= # START SYSTEMD SERVICE diff --git a/scripts/remove b/scripts/remove index b88efa1..e61e3c0 100644 --- a/scripts/remove +++ b/scripts/remove @@ -151,6 +151,16 @@ then ynh_exec_warn_less yunohost firewall disallow TCP $rtmp_port fi +#================================================= +# SPECIFIC REMOVE +#================================================= +# REMOVE VARIOUS FILES +#================================================= +ynh_script_progression --message="Removing various files..." + +# Remove the log files +ynh_secure_remove --file="/var/log/$app" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 08d1ae6..d12ada6 100644 --- a/scripts/restore +++ b/scripts/restore @@ -60,7 +60,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 --home_dir=$final_path +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE THE APP MAIN DIR @@ -99,9 +99,6 @@ ynh_install_nodejs --nodejs_version=$NODEJS_VERSION # Install dependencies ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies -# 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" - if ! yunohost app list | grep -q "prosody" then yunohost tools update @@ -143,6 +140,8 @@ systemctl enable $app.service --quiet #================================================= ynh_script_progression --message="Restoring the logrotate configuration..." +mkdir -p "/var/log/$app" +chown -R $app:$app "/var/log/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= @@ -150,7 +149,7 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description="$app daemon for Peertube" --log="$datadir/logs/peertube.log" --needs_exposed_ports $rtmp_port +yunohost service add $app --description="$app daemon for Peertube" --log="/var/log/$app/$app.log" --needs_exposed_ports $rtmp_port #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index 1782ea2..83b35b5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -143,13 +143,18 @@ fi ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/15-nginx_$app" yunohost tools regen-conf nginx +# Remove old log file +ynh_secure_remove --file="$datadir/logs" +mkdir -p "/var/log/$app" +chown -R $app:$app "/var/log/$app" + #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Making sure dedicated system user exists..." # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$final_path +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -236,9 +241,9 @@ ynh_script_progression --message="Creating a data directory..." mkdir -p $datadir -chmod 750 "$datadir/.." -chmod -R o-rwx "$datadir/.." -chown -R $app:www-data "$datadir/.." +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:www-data "$datadir" #================================================= # UPDATE A CONFIG FILE @@ -261,6 +266,7 @@ ynh_script_progression --message="Building Yarn dependencies..." pushd "$final_path" ynh_use_nodejs ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --production --pure-lockfile + ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn cache clean popd #================================================= @@ -331,7 +337,7 @@ ynh_use_logrotate --non-append #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description="$app daemon for Peertube" --log="$datadir/logs/peertube.log" --needs_exposed_ports $rtmp_port +yunohost service add $app --description="$app daemon for Peertube" --log="/var/log/$app/$app.log" --needs_exposed_ports $rtmp_port #================================================= # START SYSTEMD SERVICE