diff --git a/conf/mastodon-sidekiq.service b/conf/mastodon-sidekiq.service index 47ae8ed..d9c54a0 100644 --- a/conf/mastodon-sidekiq.service +++ b/conf/mastodon-sidekiq.service @@ -14,7 +14,8 @@ Environment="__YNH_RUBY_LOAD_PATH__" ExecStart=__INSTALL_DIR__/live/bin/bundle exec sidekiq -c 25 TimeoutSec=15 Restart=always -StandardError=syslog +StandardOutput=append:/var/log/__APP__/__APP__-sidekiq.log +StandardError=inherit # Sandboxing options to harden security # Depending on specificities of your service/app, you may need to tweak these diff --git a/conf/mastodon-streaming.service b/conf/mastodon-streaming.service index a5fcfa0..f63945e 100644 --- a/conf/mastodon-streaming.service +++ b/conf/mastodon-streaming.service @@ -13,7 +13,8 @@ Environment="__YNH_NODE_LOAD_PATH__" ExecStart=__YNH_NODE__ ./streaming TimeoutSec=15 Restart=always -StandardError=syslog +StandardOutput=append:/var/log/__APP__/__APP__-streaming.log +StandardError=inherit # Sandboxing options to harden security # Depending on specificities of your service/app, you may need to tweak these diff --git a/conf/mastodon-web.service b/conf/mastodon-web.service index 5fc8819..133fc3b 100644 --- a/conf/mastodon-web.service +++ b/conf/mastodon-web.service @@ -14,7 +14,8 @@ ExecStart=__INSTALL_DIR__/live/bin/bundle exec puma -C config/puma.rb ExecReload=/bin/kill -SIGUSR1 $MAINPID TimeoutSec=15 Restart=always -StandardError=syslog +StandardOutput=append:/var/log/__APP__/__APP__-web.log +StandardError=inherit # Sandboxing options to harden security # Depending on specificities of your service/app, you may need to tweak these diff --git a/scripts/backup b/scripts/backup index 7df8f50..2cd6afd 100644 --- a/scripts/backup +++ b/scripts/backup @@ -29,6 +29,11 @@ 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 67f48d3..d0fd3dc 100644 --- a/scripts/install +++ b/scripts/install @@ -143,6 +143,11 @@ yunohost service add "$app-streaming" --description="$app streaming service" # Create a cron file ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" +# Use logrotate to manage application logfile(s) +mkdir /var/log/$app +chown $app:$app /var/log/$app +ynh_use_logrotate + #================================================= # GENERIC FINALIZATION #================================================= @@ -150,9 +155,9 @@ ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" #================================================= ynh_script_progression --message="Starting all systemd services..." --weight=1 -ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on" -ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded" -ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening" +ynh_systemd_action --service_name=${app}-web --action="start" --log_path=/var/log/$app/$app-web.log --line_match="Listening on" +ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=/var/log/$app/$app-sidekiq.log --line_match="Schedules Loaded" +ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=/var/log/$app/$app-streaming.log --line_match="Worker 1 now listening" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 800687d..7df4fda 100644 --- a/scripts/remove +++ b/scripts/remove @@ -48,6 +48,9 @@ ynh_remove_nginx_config # Remove a cron file ynh_secure_remove --file="/etc/cron.d/$app" +# Remote logrotate config +ynh_remove_logrotate + # Remove metapackage and its dependencies ynh_remove_ruby ynh_remove_nodejs diff --git a/scripts/restore b/scripts/restore index f4703a6..5c5ea32 100644 --- a/scripts/restore +++ b/scripts/restore @@ -89,6 +89,10 @@ yunohost service add "$app-streaming" --description="$app streaming service" ynh_restore_file --origin_path="/etc/cron.d/$app" +mkdir -p /var/log/$app +chown -R $app:$app /var/log/$app +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + #================================================= # GENERIC FINALIZATION #================================================= @@ -96,9 +100,9 @@ ynh_restore_file --origin_path="/etc/cron.d/$app" #================================================= ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 -ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on" -ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded" -ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening" +ynh_systemd_action --service_name=${app}-web --action="start" --log_path=/var/log/$app/$app-web.log --line_match="Listening on" +ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=/var/log/$app/$app-sidekiq.log --line_match="Schedules Loaded" +ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=/var/log/$app/$app-streaming.log --line_match="Worker 1 now listening" ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index f2058d1..36efc8c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -72,9 +72,9 @@ ynh_remove_extra_repo #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=1 -ynh_systemd_action --service_name=${app}-web --action="stop" --log_path=systemd --line_match="Stopped" -ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=systemd --line_match="Stopped" -ynh_systemd_action --service_name=${app}-streaming --action="stop" --log_path=systemd --line_match="Stopped" +ynh_systemd_action --service_name=${app}-web --action="stop" --log_path=/var/log/$app/$app-web.log --line_match="Stopped" +ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=/var/log/$app/$app-sidekiq.log --line_match="Stopped" +ynh_systemd_action --service_name=${app}-streaming --action="stop" --log_path=/var/log/$app/$app-streaming.log --line_match="Stopped" #================================================= # ADD SWAP IF NEEDED @@ -156,6 +156,11 @@ yunohost service add "$app-streaming" --description="$app streaming service" ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" +# Use logrotate to manage app-specific logfile(s) +mkdir -p /var/log/$app +chown $app:$app /var/log/$app +ynh_use_logrotate --non-append + #================================================= # RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) #================================================= @@ -186,9 +191,9 @@ popd #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on" -ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded" -ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening" +ynh_systemd_action --service_name=${app}-web --action="start" --log_path=/var/log/$app/$app-web.log --line_match="Listening on" +ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=/var/log/$app/$app-sidekiq.log --line_match="Schedules Loaded" +ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=/var/log/$app/$app-streaming.log --line_match="Worker 1 now listening" #================================================= # END OF SCRIPT