From 8e470c76defd41aa6e67dcb0897471958d5d0e30 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Tue, 8 Jan 2019 22:17:04 +0100 Subject: [PATCH] Add dedicated log files and yunohost service --- conf/funkwhale-beat.service | 6 +++++- conf/funkwhale-server.service | 6 +++++- conf/funkwhale-worker.service | 6 +++++- scripts/install | 9 +++++++++ scripts/remove | 23 +++++++++++++++++++++++ scripts/restore | 8 ++++++++ 6 files changed, 55 insertions(+), 3 deletions(-) diff --git a/conf/funkwhale-beat.service b/conf/funkwhale-beat.service index da75461..0ed3a3e 100644 --- a/conf/funkwhale-beat.service +++ b/conf/funkwhale-beat.service @@ -8,7 +8,11 @@ User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/code/api EnvironmentFile=__FINALPATH__/code/config/.env -ExecStart=__FINALPATH__/code/virtualenv/bin/celery -A funkwhale_api.taskapp beat -l INFO + +# https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RuntimeDirectory= +LogsDirectory=__APP__ +ExecStart=__FINALPATH__/code/virtualenv/bin/celery -A funkwhale_api.taskapp beat \ + --loglevel INFO --logfile=/var/log/__APP__/beat.log NoNewPrivileges=true PrivateDevices=true diff --git a/conf/funkwhale-server.service b/conf/funkwhale-server.service index 2e5705d..2120af4 100644 --- a/conf/funkwhale-server.service +++ b/conf/funkwhale-server.service @@ -8,7 +8,11 @@ User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/code/api EnvironmentFile=__FINALPATH__/code/config/.env -ExecStart=__FINALPATH__/code/virtualenv/bin/daphne -b ${FUNKWHALE_API_IP} -p ${FUNKWHALE_API_PORT} config.asgi:application --proxy-headers + +# https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RuntimeDirectory= +LogsDirectory=__APP__ +ExecStart=__FINALPATH__/code/virtualenv/bin/daphne -b ${FUNKWHALE_API_IP} -p ${FUNKWHALE_API_PORT} config.asgi:application --proxy-headers \ + --loglevel INFO --logfile=/var/log/__APP__/server.log NoNewPrivileges=true PrivateDevices=true diff --git a/conf/funkwhale-worker.service b/conf/funkwhale-worker.service index 2a8bfbf..cddd114 100644 --- a/conf/funkwhale-worker.service +++ b/conf/funkwhale-worker.service @@ -8,7 +8,11 @@ User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/code/api EnvironmentFile=__FINALPATH__/code/config/.env -ExecStart=__FINALPATH__/code/virtualenv/bin/celery -A funkwhale_api.taskapp worker -l INFO + +# https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RuntimeDirectory= +LogsDirectory=__APP__ +ExecStart=__FINALPATH__/code/virtualenv/bin/celery -A funkwhale_api.taskapp worker -l INFO \ + --loglevel INFO --logfile=/var/log/__APP__/worker.log NoNewPrivileges=true PrivateDevices=true diff --git a/scripts/install b/scripts/install index 767341f..a0ed44d 100644 --- a/scripts/install +++ b/scripts/install @@ -228,6 +228,15 @@ chmod -R 755 "$final_path/code/front/dist/" ynh_add_fail2ban_config "/var/log/nginx/$domain-access.log" ".* \"POST /api/v1/token/ HTTP/1.1\" 400 68.*$" 5 + +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +yunohost service add "$app-server" --log "/var/log/$app/server.log" +yunohost service add "$app-worker" --log "/var/log/$app/worker.log" +yunohost service add "$app-beat" --log "/var/log/$app/beat.log" + #================================================= # SETUP SSOWAT #================================================= diff --git a/scripts/remove b/scripts/remove index c033696..afa46f7 100644 --- a/scripts/remove +++ b/scripts/remove @@ -37,6 +37,29 @@ ynh_remove_systemd_config "$app-beat" ynh_secure_remove "/etc/systemd/system/$app.target" +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL +#================================================= + +# Remove a service from the admin panel, added by `yunohost service add` +if yunohost service status | grep -q "$app-server" +then + echo "Remove $app-server service" + yunohost service remove "$app-server" +fi + +if yunohost service status | grep -q "$app-worker" +then + echo "Remove $app-worker service" + yunohost service remove "$app-worker" +fi + +if yunohost service status | grep -q "$app-beat" +then + echo "Remove $app-beat service" + yunohost service remove "$app-beat" +fi + #================================================= # REMOVE THE PostgreSQL DATABASE #================================================= diff --git a/scripts/restore b/scripts/restore index 3c3a96b..c40b1dd 100644 --- a/scripts/restore +++ b/scripts/restore @@ -115,6 +115,14 @@ ynh_psql_execute_file_as_root ./db.sql "$db_name" # Restore permissions on app files chown -R "$app": "$final_path" +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +yunohost service add "$app-server" --log "/var/log/$app/server.log" +yunohost service add "$app-worker" --log "/var/log/$app/worker.log" +yunohost service add "$app-beat" --log "/var/log/$app/beat.log" + #================================================= # RESTORE SYSTEMD #=================================================