From 2f8406f991202875aaee870491c08b5722d12968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Mon, 17 Aug 2020 22:00:52 +0200 Subject: [PATCH] Patch (#7) * Add log file in /var/log/navidrome folder (fix #5) * Add data folder path to navidrome.toml --- README.md | 4 ++-- README_fr.md | 2 +- conf/navidrome.toml | 1 + conf/systemd.service | 2 ++ scripts/backup | 6 ++++++ scripts/change_url | 2 +- scripts/install | 16 ++++++++++++++-- scripts/remove | 9 +++++++++ scripts/restore | 10 ++++++++-- scripts/upgrade | 13 +++++++++++-- 10 files changed, 55 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1956835..79253de 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,9 @@ Navidrome is an open source web-based music collection server and streamer. It g ## Configuration -You can configure Navidrome by editing this file `/var/lib/navidrome/navidrome.toml` using the [documentation](https://www.navidrome.org/docs/usage/configuration-options/); +You can configure Navidrome by editing this file `/var/lib/navidrome/navidrome.toml` using the [documentation](https://www.navidrome.org/docs/usage/configuration-options/). -The music is to be stored in the folder `/home/yunohost.navidrome/Music`. +The media storage folder is by default set to `/home/yunohost.navidrome/Music`. You can customize it by editing the `MusicFolder` option in the `/var/lib/navidrome/navidrome.toml` file. ## Documentation diff --git a/README_fr.md b/README_fr.md index f939941..f1ed768 100644 --- a/README_fr.md +++ b/README_fr.md @@ -25,7 +25,7 @@ Navidrome est un serveur et un streamer de collection de musique en ligne open s Vous pouvez configurer Navidrome en modifiant le fichier `/var/lib/navidrome/navidrome.toml` et en vous aidant de la [documentation](https://www.navidrome.org/docs/usage/configuration-options/). -La musique est à stocker dans le dossier `/home/yunohost.navidrome/Music`. +Le dossier de stockage des médias est par défaut `/home/yunohost.navidrome/Music`. Vous pouvez le personnaliser en éditant l'option `MusicFolder` dans le fichier `/var/lib/navidrome/navidrome.toml`. ## Documentation diff --git a/conf/navidrome.toml b/conf/navidrome.toml index a8715df..fce04bf 100644 --- a/conf/navidrome.toml +++ b/conf/navidrome.toml @@ -4,4 +4,5 @@ Port = "__PORT__" BaseURL = "__PATH_URL__" ScanInterval = "90s" TranscodingCacheSize = "150MiB" +DataFolder = "__CONFIG_PATH__" MusicFolder = "/home/yunohost.navidrome/Music" diff --git a/conf/systemd.service b/conf/systemd.service index 3402c6e..2649efc 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -15,6 +15,8 @@ WorkingDirectory=__CONFIG_PATH__ TimeoutStopSec=20 KillMode=process Restart=on-failure +StandardOutput=append:/var/log/__APP__/__APP__.log +StandardError=inherit # See https://www.freedesktop.org/software/systemd/man/systemd.exec.html DevicePolicy=closed diff --git a/scripts/backup b/scripts/backup index 5b83cfc..d66fb5b 100644 --- a/scripts/backup +++ b/scripts/backup @@ -54,6 +54,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/change_url b/scripts/change_url index 126bdb3..0568b86 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -109,7 +109,7 @@ fi ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Version:" +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Version:" #================================================= # RELOAD NGINX diff --git a/scripts/install b/scripts/install index 7f09e5c..38b2c17 100644 --- a/scripts/install +++ b/scripts/install @@ -119,6 +119,7 @@ cp ../conf/navidrome.toml "$config_path/navidrome.toml" # Main config File ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_path/navidrome.toml" ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="$config_path/navidrome.toml" +ynh_replace_string --match_string="__CONFIG_PATH__" --replace_string="$config_path" --target_file="$config_path/navidrome.toml" ynh_store_file_checksum --file="$config_path/navidrome.toml" @@ -148,12 +149,23 @@ chown -R $app:$app "$config_path" chown -R $app:www-data /home/yunohost.$app/ chmod -R 764 /home/yunohost.$app +#================================================= +# HANDLE LOG FILES AND SETUP LOGROTATE +#================================================= +ynh_script_progression --message="Configuring log rotation..." --weight=1 + +mkdir -p /var/log/$app +touch /var/log/$app/$app.log +chown $app -R /var/log/$app + +ynh_use_logrotate + #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description "Web-based music collection server and streamer" +yunohost service add $app --description "Web-based music collection server and streamer" --log "/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE @@ -161,7 +173,7 @@ yunohost service add $app --description "Web-based music collection server and s 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="Version:" +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Version:" #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index c1a3d15..448b919 100644 --- a/scripts/remove +++ b/scripts/remove @@ -73,6 +73,15 @@ 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 logs and logrotate configuration..." --weight=1 + +ynh_secure_remove --file="/var/log/$app" + +ynh_remove_logrotate + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 9d2faec..33422df 100644 --- a/scripts/restore +++ b/scripts/restore @@ -103,14 +103,20 @@ systemctl enable $app.service #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description "Web-based music collection server and streamer" +yunohost service add $app --description "Web-based music collection server and streamer" --log_path="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Version:" +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Version:" + +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 050fb9e..7fda7aa 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -116,6 +116,7 @@ cp ../conf/navidrome.toml "$config_path/navidrome.toml" # Main config File ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config_path/navidrome.toml" ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="$config_path/navidrome.toml" +ynh_replace_string --match_string="__CONFIG_PATH__" --replace_string="$config_path" --target_file="$config_path/navidrome.toml" ynh_store_file_checksum --file="$config_path/navidrome.toml" @@ -146,19 +147,27 @@ chown -R $app:$app $config_path chown -R $app:www-data /home/yunohost.$app/ chmod -R 764 /home/yunohost.$app +#================================================= +# SETUP LOGROTATE +#================================================= +ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1 + +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append + #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description "Web-based music collection server and streamer" +yunohost service add $app --description "Web-based music collection server and streamer" --log_path="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Version:" +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Version:" #================================================= # RELOAD NGINX