From efee1e5c05167dac701022ae79526aa98a73ecac Mon Sep 17 00:00:00 2001 From: trendless Date: Mon, 15 Jun 2026 18:39:50 -0600 Subject: [PATCH] adjust logging for v15 changes --- conf/logsymlink.cron | 1 + conf/systemd.service | 2 +- scripts/backup | 8 +------- scripts/change_url | 4 ++-- scripts/install | 24 ++++++++++++++++-------- scripts/remove | 9 +++------ scripts/restore | 14 +++++++++----- scripts/upgrade | 24 ++++++++++++++++-------- 8 files changed, 49 insertions(+), 37 deletions(-) create mode 100644 conf/logsymlink.cron diff --git a/conf/logsymlink.cron b/conf/logsymlink.cron new file mode 100644 index 0000000..ebac0a6 --- /dev/null +++ b/conf/logsymlink.cron @@ -0,0 +1 @@ +0,15,30,45 0 * * * ln -sf $(ls -t /var/log/__APP__/dns/*.log | head -n 1) /var/log/__APP__/__APP__.log \ No newline at end of file diff --git a/conf/systemd.service b/conf/systemd.service index bd24e65..e608a57 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -9,10 +9,10 @@ Group=__APP__ WorkingDirectory=__INSTALL_DIR__/sources/ ExecStart=__INSTALL_DIR__/dotnet/dotnet __INSTALL_DIR__/sources/DnsServerApp.dll __DATA_DIR__ Restart=always -# Restart service after 10 seconds if the dotnet service crashes: RestartSec=10 KillSignal=SIGINT SyslogIdentifier=dns-server +Environment=DNS_SERVER_LOG_FOLDER_PATH=/var/log/__APP__/dns [Install] WantedBy=multi-user.target diff --git a/scripts/backup b/scripts/backup index c7a5f5a..edcfa03 100755 --- a/scripts/backup +++ b/scripts/backup @@ -11,30 +11,24 @@ ynh_print_info "Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= - ynh_backup "$install_dir" #================================================= # BACKUP THE DATA DIR #================================================= - ynh_backup "$data_dir" #================================================= # SYSTEM CONFIGURATION #================================================= - ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_backup "/etc/logrotate.d/$app" - ynh_backup "/etc/systemd/system/$app.service" #================================================= # BACKUP VARIOUS FILES #================================================= - -ynh_backup "/var/log/technitium/" +ynh_backup "/var/log/$app" #================================================= # END OF SCRIPT diff --git a/scripts/change_url b/scripts/change_url index 5882bc4..4c167dd 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -11,7 +11,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_script_progression "Stopping $app's systemd service..." -ynh_systemctl --service="$app" --action="stop" --wait_until="was stopped successfully" +ynh_systemctl --service="$app" --action="stop" --log_path=systemd --wait_until="was stopped successfully" #================================================= # MODIFY URL IN NGINX CONF @@ -25,7 +25,7 @@ ynh_config_change_url_nginx #================================================= ynh_script_progression "Starting $app's systemd service..." -ynh_systemctl --service="$app" --action="start" --wait_until="in web browser to access web console." +ynh_systemctl --service="$app" --action="start" --log_path=systemd --wait_until="was started successfully" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index b96497b..39fe304 100755 --- a/scripts/install +++ b/scripts/install @@ -11,7 +11,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_script_progression "Setting up source files..." -# Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --source_id="prebuilt" --dest_dir="$install_dir/sources" ynh_setup_source --source_id="dotnet" --dest_dir="$install_dir/dotnet" @@ -20,23 +19,32 @@ ynh_setup_source --source_id="dotnet" --dest_dir="$install_dir/dotnet" #================================================= ynh_script_progression "Adding system configurations related to $app..." -# Create a dedicated NGINX config ynh_config_add_nginx -# Create a dedicated systemd config ynh_config_add_systemd -yunohost service add "$app" --description="Technitium DNS Server" --log="/var/log/technitium/$app.log" --needs_exposed_ports="53" -# Use logrotate to manage application logfile(s) -ynh_config_add_logrotate /var/log/technitium/dns +mkdir -p "/var/log/$app/dns" +chown -R "$app:$app" "/var/log/$app" + +yunohost service add "$app" --description="Technitium DNS Server" --log="/var/log/$app/$app.log" --needs_exposed_ports="53" + +#================================================= +# ADD A CRON JOB +#================================================= +ynh_config_add --template="logsymlink.cron" --destination="/etc/cron.d/$app" +chmod 644 "/etc/cron.d/$app" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression "Starting $app's systemd service..." -# Start a systemd service -ynh_systemctl --service="$app" --action="start" --wait_until="^.*in web browser to access web console\\.$" +ynh_systemctl --service="$app" --action="restart" --log_path=systemd --wait_until="was started successfully" + +#================================================= +# LINK LOGS +#================================================= +ln -sf $(ls -t /var/log/$app/dns/*.log | head -n 1) /var/log/$app/$app.log #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 59c5469..0e8c640 100755 --- a/scripts/remove +++ b/scripts/remove @@ -16,16 +16,13 @@ if ynh_hide_warnings yunohost service status "$app" >/dev/null; then yunohost service remove "$app" fi -# Remove the dedicated systemd config ynh_config_remove_systemd -# Remove the app-specific logrotate config -ynh_config_remove_logrotate - -# Remove the dedicated NGINX config ynh_config_remove_nginx -# Remove the log files +ynh_safe_rm "/var/log/$app" + +ynh_safe_rm "/etc/cron.d/$app" #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 24d9b08..ff6bc9a 100755 --- a/scripts/restore +++ b/scripts/restore @@ -27,20 +27,24 @@ ynh_script_progression "Restoring system configurations related to $app..." ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore "/var/log/$app" + ynh_restore "/etc/systemd/system/$app.service" systemctl enable "$app.service" --quiet -yunohost service add "$app" --description="Technitium DNS Server" --log="/var/log/technitium/$app.log" --needs_exposed_ports=53 +yunohost service add "$app" --description="Technitium DNS Server" --log="/var/log/$app/$app.log" --needs_exposed_ports=53 -ynh_restore "/etc/logrotate.d/$app" -mkdir -p /var/log/technitium/dns -chown -R $app:$app /var/log/technitium +#================================================= +# ADD A CRON JOB +#================================================= +ynh_config_add --template="logsymlink.cron" --destination="/etc/cron.d/$app" +chmod 644 "/etc/cron.d/$app" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression "Starting $app's systemd service..." -ynh_systemctl --service="$app" --action="start" --wait_until="in web browser to access web console." +ynh_systemctl --service="$app" --action="start" --log_path=systemd --wait_until="was started successfully" #================================================= # RELOAD NGINX diff --git a/scripts/upgrade b/scripts/upgrade index 6267bb8..2342651 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -11,7 +11,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_script_progression "Stopping $app's systemd service..." -ynh_systemctl --service=$app --action="stop" --wait_until="was stopped successfully" +ynh_systemctl --service="$app" --action="stop" --log_path=systemd --wait_until="was stopped successfully" #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -24,12 +24,19 @@ if [ ! -d "$install_dir/dotnet" ]; then ynh_safe_rm "/usr/bin/dotnet" fi +if ynh_app_upgrading_from_version_before_or_equal_to 14.3.0~ynh1; then + mkdir -p "/var/log/$app" + mv "$data_dir/logs" "/var/log/$app/dns" + chown -R "$app:$app" "/var/log/$app" + ln -sf "/var/log/$app/dns" "$data_dir/logs" + ln -sf $(ls -t /var/log/$app/dns/*.log | head -n 1) /var/log/$app/$app.log +fi + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression "Upgrading source files..." -# Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --source_id="prebuilt" --dest_dir="$install_dir/sources" --full_replace ynh_setup_source --source_id="dotnet" --dest_dir="$install_dir/dotnet" --full_replace @@ -38,22 +45,23 @@ ynh_setup_source --source_id="dotnet" --dest_dir="$install_dir/dotnet" --full_re #================================================= ynh_script_progression "Upgrading system configurations related to $app..." -# Create a dedicated NGINX config ynh_config_add_nginx -# Create a dedicated systemd config ynh_config_add_systemd -yunohost service add "$app" --description="Technitium DNS Server" --log="/var/log/technitium/$app.log" --needs_exposed_ports=53 +yunohost service add "$app" --description="Technitium DNS Server" --log="/var/log/$app/$app.log" --needs_exposed_ports=53 -# Use logrotate to manage app-specific logfile(s) -ynh_config_add_logrotate /var/log/technitium/dns +#================================================= +# ADD A CRON JOB +#================================================= +ynh_config_add --template="logsymlink.cron" --destination="/etc/cron.d/$app" +chmod 644 "/etc/cron.d/$app" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression "Starting $app's systemd service..." -ynh_systemctl --service="$app" --action="start" --wait_until="in web browser to access web console." +ynh_systemctl --service="$app" --action="start" --log_path=systemd --wait_until="was started successfully" #================================================= # END OF SCRIPT