From b4418b142acf7c50d0df4a27ce40dcd9c71a26ed Mon Sep 17 00:00:00 2001 From: tituspijean Date: Fri, 2 Feb 2024 20:07:47 +0100 Subject: [PATCH] Initial packaging --- conf/watchdog.conf | 5 ++++ doc/DESCRIPTION.md | 4 ++++ manifest.toml | 33 ++++++++++++++++++++++++++ scripts/backup | 25 ++++++++++++++++++++ scripts/install | 59 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/remove | 37 +++++++++++++++++++++++++++++ scripts/restore | 28 ++++++++++++++++++++++ scripts/upgrade | 57 ++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 248 insertions(+) create mode 100644 conf/watchdog.conf create mode 100644 doc/DESCRIPTION.md create mode 100644 manifest.toml create mode 100644 scripts/backup create mode 100644 scripts/install create mode 100644 scripts/remove create mode 100644 scripts/restore create mode 100644 scripts/upgrade diff --git a/conf/watchdog.conf b/conf/watchdog.conf new file mode 100644 index 0000000..209035a --- /dev/null +++ b/conf/watchdog.conf @@ -0,0 +1,5 @@ +# This file has been generated by watchdog_ynh +# If your device hardware watchdog is not /dev/watchdog, feel free to alter it here and report your findings to YunoHost! +watchdog-device = /dev/watchdog +watchdog-timeout = 15 +max-load-1 = 24 diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..0b1044e --- /dev/null +++ b/doc/DESCRIPTION.md @@ -0,0 +1,4 @@ +A Watchdog device makes sure that your server is still running. +The included service will regularly write to that watchdog device. If it stops doing so, most likely due to a freeze, then the server will be rebooted. + +This Watchdog better (only?) works if you have a hardware watchdog integrated in your server. It has only been tested on Raspberry Pi so far. diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..f1b8122 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,33 @@ +packaging_format = 2 + +id = "watchdog" +name = "Watchdog" + +description.en = "Automatically reboot your server in case of freeze" +description.fr = "Redémarre automatiquement votre serveur en cas de plantage" + +version = "5.16~ynh1" + +maintainers = ["tituspijean"] + +[upstream] +license = "GPL-2.0-or-later" + +code = "https://sourceforge.net/projects/watchdog/" + +[integration] +yunohost = ">= 11.2" +architectures = "all" +multi_instance = false +ldap = "not_relevant" +sso = "not_relevant" +disk = "50M" +ram.build = "50M" +ram.runtime = "50M" + +[install] + +[resources] + + [resources.apt] + packages = "watchdog" diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..a1475cf --- /dev/null +++ b/scripts/backup @@ -0,0 +1,25 @@ +#!/bin/bash +#### App file generated with YoloGen, the YunoHost app generator, version . + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +source ../settings/scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." + +ynh_backup --src_path="/etc/watchdog.conf" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install new file mode 100644 index 0000000..fad81f0 --- /dev/null +++ b/scripts/install @@ -0,0 +1,59 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# INSTALL DEPENDENCIES +#================================================= + +#================================================= +# SYSTEM CONFIGURATION +#================================================= +ynh_script_progression --message="Adding system configurations related to $app..." + +reboot_required=false +if [[ $(grep -ic "Raspberry Pi" /proc/cpuinfo) -ge 1 && $(grep -ic "dtparam=watchdog=on" /boot/config.txt) -eq 0 ]]; then + echo "dtparam=watchdog=on" >> /boot/config.txt + reboot_required=true +fi + +yunohost service add $app + +#================================================= +# APP INITIAL CONFIGURATION +#================================================= +# ADD A CONFIGURATION +#================================================= +ynh_script_progression --message="Adding app's configuration file..." + +ynh_add_config --template="watchdog.conf" --destination="/etc/watchdog.conf" + +chmod 400 "/etc/watchdog.conf" +chown root: "/etc/watchdog.conf" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting app's systemd service..." + +# Enable and start a systemd service +systemctl enable $app.service --quiet +ynh_systemd_action --service_name=$app --action="start" + +#================================================= +# END OF SCRIPT +#================================================= + +if [ reboot_required = true ]; then + echo "Your device boot configuration has been updated to enable the hardware watchdog. Please reboot it." > ../doc/POST_INSTALL.md +else + rm ../doc/POST_INSTALL.md +fi + +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove new file mode 100644 index 0000000..97ae1b9 --- /dev/null +++ b/scripts/remove @@ -0,0 +1,37 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# REMOVE SYSTEM CONFIGURATIONS +#================================================= +# REMOVE SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Removing system configurations related to $app..." + +# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) +if ynh_exec_warn_less yunohost service status $app >/dev/null +then + ynh_script_progression --message="Removing $app service integration..." + yunohost service remove $app +fi + +ynh_remove_systemd_config + +ynh_remove_nginx_config + +# Remove other various files specific to the app... such as : + +ynh_secure_remove --file="/var/log/$app" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" --last \ No newline at end of file diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..f014257 --- /dev/null +++ b/scripts/restore @@ -0,0 +1,28 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +source ../settings/scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RESTORE SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 + +ynh_restore_file --origin_path="/etc/watchdog.conf" + +systemctl enable $app.service --quiet + +yunohost service add $app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..9373126 --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,57 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +upgrade_type=$(ynh_check_app_version_changed) + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= + +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" + +#================================================= +# REAPPLY SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Upgrading system configurations related to $app..." + +yunohost service add $app + +#================================================= +# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) +#================================================= +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a configuration file..." + +ynh_add_config --template="watchdog.conf" --destination="/etc/watchdog.conf" + +chmod 400 "/etc/watchdog.conf" +chown root: "/etc/watchdog.conf" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action="start" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed" --last