1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/uptime-kuma_ynh.git synced 2024-10-01 13:34:58 +02:00

add backup, restore and upgrade scripts + notes on post-install

This commit is contained in:
Hadrien 2021-11-02 08:19:30 +03:00
parent 8539138446
commit 8b7e64c3d8
8 changed files with 193 additions and 203 deletions

View file

@ -42,10 +42,8 @@ It is a self-hosted monitoring tool like "Uptime Robot".
- Requires a full dedicated domain - Requires a full dedicated domain
- ARM architecture not supported - ARM architecture not supported
- This app needs a manual post-install - This app needs a manual post-install
- No upgrade script in this package
- No restore script in this package
- Backup script is untested in this package
- Uses N to install specific nodejs version - Uses N to install specific nodejs version
- We could pre-configure mail notifications with YunoHost mail server as an improvement.
<!-- * Any known limitations, constrains or stuff not working, such as (but not limited to): <!-- * Any known limitations, constrains or stuff not working, such as (but not limited to):
* requiring a full dedicated domain ? * requiring a full dedicated domain ?
* architectures not supported ? * architectures not supported ?

View file

@ -38,10 +38,8 @@ It is a self-hosted monitoring tool like "Uptime Robot".
- Requires a full dedicated domain - Requires a full dedicated domain
- ARM architecture not supported - ARM architecture not supported
- This app needs a manual post-install - This app needs a manual post-install
- No upgrade script in this package
- No restore script in this package
- Backup script is untested in this package
- Uses N to install specific nodejs version - Uses N to install specific nodejs version
- We could pre-configure mail notifications with YunoHost mail server as an improvement.
<!-- * Any known limitations, constrains or stuff not working, such as (but not limited to): <!-- * Any known limitations, constrains or stuff not working, such as (but not limited to):
* requiring a full dedicated domain ? * requiring a full dedicated domain ?
* architectures not supported ? * architectures not supported ?

View file

@ -1,10 +1,8 @@
- Requires a full dedicated domain - Requires a full dedicated domain
- ARM architecture not supported - ARM architecture not supported
- This app needs a manual post-install - This app needs a manual post-install
- No upgrade script in this package
- No restore script in this package
- Backup script is untested in this package
- Uses N to install specific nodejs version - Uses N to install specific nodejs version
- We could pre-configure mail notifications with YunoHost mail server as an improvement.
<!-- * Any known limitations, constrains or stuff not working, such as (but not limited to): <!-- * Any known limitations, constrains or stuff not working, such as (but not limited to):
* requiring a full dedicated domain ? * requiring a full dedicated domain ?
* architectures not supported ? * architectures not supported ?

View file

@ -48,13 +48,13 @@ ynh_print_info --message="Declaring files to be backed up..."
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_backup --src_path="$final_path" ynh_backup --src_path="$final_path" --is_big
#================================================= #=================================================
# BACKUP THE DATA DIR # BACKUP THE DATA DIR
#================================================= #=================================================
ynh_backup --src_path="$datadir" --is_big ynh_backup --src_path="$datadir"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION
@ -95,7 +95,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
# ynh_backup --src_path="/etc/cron.d/$app" # ynh_backup --src_path="/etc/cron.d/$app"
ynh_backup --src_path="/etc/$app/" # ynh_backup --src_path="/etc/$app/"
#================================================= #=================================================
# BACKUP THE MYSQL DATABASE # BACKUP THE MYSQL DATABASE

View file

@ -295,22 +295,20 @@ ynh_script_progression --message="Configuring a systemd service..." --time --wei
ynh_add_systemd_config ynh_add_systemd_config
#================================================= #=================================================
# SETUP APPLICATION WITH CURL # SETUP APPLICATION
#================================================= #=================================================
### We cannot use it since this app uses websocket exclusively. ### It could be tricky to use CURL since this app uses websocket exclusively.
# curl --data-binary '{"jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "1"}' -H "Upgrade:websocket" -H 'content-type: application/json;' http://localhost:9090/jsonrpc
# # Set the app as temporarily public for curl call ### We could write to its SQLite. Didn't find where the language preferences are though.
# ynh_script_progression --message="Configuring SSOwat..." --time --weight=1
# # Making the app public for curl
# ynh_permission_update --permission="main" --add="visitors"
# # Installation with curl # password_hashed = $(htpasswd -bnBC 10 "" $password | tr -d ':\n')
# ynh_script_progression --message="Finalizing installation..." --time --weight=1 # sqlite3 $final_path/db/kuma.db <<EOF
# ynh_local_curl "/" "key1=value1" "key2=value2" "key3=value3" # INSERT INTO "main"."user" ("id", "username", "password", "active", "timezone", "twofa_secret", "twofa_status", "twofa_last_token") VALUES ('1', '$admin', '$password_hashed', '1', '', '', '0', '');
# EOF
# # Remove the public access ### We could pre-configure mail notifications.
# ynh_permission_update --permission="main" --remove="visitors"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION

View file

@ -78,7 +78,7 @@ ynh_remove_nodejs
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Removing app main directory..." --time --weight=1 ynh_script_progression --message="Removing app main directory and dependencies..." --time --weight=2
# Remove the app directory securely # Remove the app directory securely
ynh_secure_remove --file="$final_path" ynh_secure_remove --file="$final_path"
@ -139,7 +139,7 @@ ynh_script_progression --message="Removing various files..." --time --weight=1
# ynh_secure_remove --file="/etc/cron.d/$app" # ynh_secure_remove --file="/etc/cron.d/$app"
# Remove a directory securely # Remove a directory securely
ynh_secure_remove --file="/etc/$app" # ynh_secure_remove --file="/etc/$app"
# Remove the log files # Remove the log files
ynh_secure_remove --file="/var/log/$app" ynh_secure_remove --file="/var/log/$app"

View file

@ -31,9 +31,9 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path) path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name) # db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name # db_user=$db_name
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) # phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
datadir=$(ynh_app_setting_get --app=$app --key=datadir) datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#================================================= #=================================================
@ -97,13 +97,6 @@ chmod 750 "$datadir"
chmod -R o-rwx "$datadir" chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir" chown -R $app:www-data "$datadir"
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
# ynh_script_progression --message="Restoring the PHP-FPM configuration..." --time --weight=1
# ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
#================================================= #=================================================
# RESTORE FAIL2BAN CONFIGURATION # RESTORE FAIL2BAN CONFIGURATION
#================================================= #=================================================
@ -115,10 +108,29 @@ chown -R $app:www-data "$datadir"
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
#=================================================
#=================================================
# INSTALL NODEJS
#=================================================
ynh_script_progression --message="Reinstalling NodeJS..." --time --weight=2
ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# NODEJS Version
#=================================================
ynh_use_nodejs
#================================================= #=================================================
# REINSTALL DEPENDENCIES # REINSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1 ynh_script_progression --message="Reinstalling dependencies..." --time --weight=7
cd $final_path && ynh_exec_warn_less $ynh_npm install
ynh_script_progression --message="Downloading Uptime Kuma frontend..." --time --weight=1
ynh_exec_warn_less wget https://github.com/louislam/uptime-kuma/releases/download/1.10.0/dist.tar.gz
ynh_exec_as $app tar -xvf dist.tar.gz --directory=$final_path
# Define and install dependencies # Define and install dependencies
# ynh_install_app_dependencies $pkg_dependencies # ynh_install_app_dependencies $pkg_dependencies
@ -135,11 +147,11 @@ ynh_script_progression --message="Reinstalling dependencies..." --time --weight=
#================================================= #=================================================
# RESTORE VARIOUS FILES # RESTORE VARIOUS FILES
#================================================= #=================================================
ynh_script_progression --message="Restoring various files..." --time --weight=1 # ynh_script_progression --message="Restoring various files..." --time --weight=1
# ynh_restore_file --origin_path="/etc/cron.d/$app" # ynh_restore_file --origin_path="/etc/cron.d/$app"
ynh_restore_file --origin_path="/etc/$app/" # ynh_restore_file --origin_path="/etc/$app/"
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
@ -175,9 +187,9 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap
#================================================= #=================================================
# RELOAD NGINX AND PHP-FPM # RELOAD NGINX AND PHP-FPM
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --time --weight=1 ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload # ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================

View file

@ -1,167 +1,153 @@
# #!/bin/bash #!/bin/bash
# See #=================================================
# https://github.com/louislam/uptime-kuma/wiki/%F0%9F%86%99-How-to-Update # GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# #================================================= source _common.sh
# # GENERIC START source /usr/share/yunohost/helpers
# #=================================================
# # IMPORT GENERIC HELPERS
# #=================================================
# source _common.sh #=================================================
# source /usr/share/yunohost/helpers # LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
# #================================================= app=$YNH_APP_INSTANCE_NAME
# # LOAD SETTINGS
# #=================================================
# ynh_script_progression --message="Loading installation settings..." --time --weight=1
# app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
# domain=$(ynh_app_setting_get --app=$app --key=domain)
# path_url=$(ynh_app_setting_get --app=$app --key=path)
# admin=$(ynh_app_setting_get --app=$app --key=admin) # admin=$(ynh_app_setting_get --app=$app --key=admin)
# final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# language=$(ynh_app_setting_get --app=$app --key=language) # language=$(ynh_app_setting_get --app=$app --key=language)
# db_name=$(ynh_app_setting_get --app=$app --key=db_name) # db_name=$(ynh_app_setting_get --app=$app --key=db_name)
# #================================================= #=================================================
# # CHECK VERSION # CHECK VERSION
# #================================================= #=================================================
# ### This helper will compare the version of the currently installed app and the version of the upstream package. ### This helper will compare the version of the currently installed app and the version of the upstream package.
# ### $upgrade_type can have 2 different values ### $upgrade_type can have 2 different values
# ### - UPGRADE_APP if the upstream app version has changed ### - UPGRADE_APP if the upstream app version has changed
# ### - UPGRADE_PACKAGE if only the YunoHost package has changed ### - UPGRADE_PACKAGE if only the YunoHost package has changed
# ### ynh_check_app_version_changed will stop the upgrade if the app is up to date. ### ynh_check_app_version_changed will stop the upgrade if the app is up to date.
# ### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do. ### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do.
# upgrade_type=$(ynh_check_app_version_changed) upgrade_type=$(ynh_check_app_version_changed)
# #================================================= #=================================================
# # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
# #================================================= #=================================================
# ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1 ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1
# # Backup the current version of the app # Backup the current version of the app
# ynh_backup_before_upgrade ynh_backup_before_upgrade
# ynh_clean_setup () { ynh_clean_setup () {
# # Restore it if the upgrade fails # Restore it if the upgrade fails
# ynh_restore_upgradebackup ynh_restore_upgradebackup
# } }
# # Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
# ynh_abort_if_errors ynh_abort_if_errors
# #================================================= #=================================================
# # STANDARD UPGRADE STEPS # STANDARD UPGRADE STEPS
# #================================================= #=================================================
# # STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
# #================================================= #=================================================
# ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 ynh_script_progression --message="Stopping a systemd service..." --time --weight=1
# ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
# #================================================= #=================================================
# # ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
# #================================================= #=================================================
# ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1 ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
# # #
# # N.B. : the followings setting migrations snippets are provided as *EXAMPLES* # N.B. : the followings setting migrations snippets are provided as *EXAMPLES*
# # of what you may want to do in some cases (e.g. a setting was not defined on # of what you may want to do in some cases (e.g. a setting was not defined on
# # some legacy installs and you therefore want to initiaze stuff during upgrade) # some legacy installs and you therefore want to initiaze stuff during upgrade)
# # #
# # If db_name doesn't exist, create it # If db_name doesn't exist, create it
# #if [ -z "$db_name" ]; then #if [ -z "$db_name" ]; then
# # db_name=$(ynh_sanitize_dbid --db_name=$app) # db_name=$(ynh_sanitize_dbid --db_name=$app)
# # ynh_app_setting_set --app=$app --key=db_name --value=$db_name # ynh_app_setting_set --app=$app --key=db_name --value=$db_name
# #fi #fi
# # If final_path doesn't exist, create it # If final_path doesn't exist, create it
# #if [ -z "$final_path" ]; then # if [ -z "$final_path" ]; then
# # final_path=/var/www/$app # final_path=/var/www/$app
# # ynh_app_setting_set --app=$app --key=final_path --value=$final_path # ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# #fi
# ### If nobody installed your app before 4.1,
# ### then you may safely remove these lines
# # Cleaning legacy permissions
# if ynh_legacy_permissions_exists; then
# ynh_legacy_permissions_delete_all
# ynh_app_setting_delete --app=$app --key=is_public
# fi # fi
# if ! ynh_permission_exists --permission="admin"; then #=================================================
# # Create the required permissions # CREATE DEDICATED USER
# ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin #=================================================
# fi ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
# # Create a permission if needed # Create a dedicated user (if not existing)
# if ! ynh_permission_exists --permission="api"; then ynh_system_user_create --username=$app --home_dir="$final_path"
# ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
# fi
# #================================================= #=================================================
# # CREATE DEDICATED USER # DOWNLOAD, CHECK AND UNPACK SOURCE
# #================================================= #=================================================
# ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
# # Create a dedicated user (if not existing) if [ "$upgrade_type" == "UPGRADE_APP" ]
# ynh_system_user_create --username=$app --home_dir="$final_path" then
ynh_script_progression --message="Upgrading source files..." --time --weight=1
# #================================================= # Download, check integrity, uncompress and patch the source from app.src
# # DOWNLOAD, CHECK AND UNPACK SOURCE ynh_setup_source --dest_dir="$final_path" --keep=data/
# #================================================= # Download, check integrity, uncompress and patch the source from dist.src
ynh_setup_source --source_id="dist" --dest_dir="$final_path/dist"
# if [ "$upgrade_type" == "UPGRADE_APP" ] fi
# then
# ynh_script_progression --message="Upgrading source files..." --time --weight=1
# # Download, check integrity, uncompress and patch the source from app.src # FIXME: this should be managed by the core in the future
# ynh_setup_source --dest_dir="$final_path" # Here, as a packager, you may have to tweak the ownerhsip/permissions
# fi # such that the appropriate users (e.g. maybe www-data) can access
# files in some cases.
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
# this will be treated as a security issue.
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
# # FIXME: this should be managed by the core in the future #=================================================
# # Here, as a packager, you may have to tweak the ownerhsip/permissions # NGINX CONFIGURATION
# # such that the appropriate users (e.g. maybe www-data) can access #=================================================
# # files in some cases. ynh_script_progression --message="Upgrading NGINX web server configuration..." --time --weight=1
# # But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
# # this will be treated as a security issue.
# chmod 750 "$final_path"
# chmod -R o-rwx "$final_path"
# chown -R $app:www-data "$final_path"
# #================================================= # Create a dedicated NGINX config
# # NGINX CONFIGURATION ynh_add_nginx_config
# #=================================================
# ynh_script_progression --message="Upgrading NGINX web server configuration..." --time --weight=1
# # Create a dedicated NGINX config #=================================================
# ynh_add_nginx_config # INSTALL NODEJS
#=================================================
ynh_script_progression --message="Upgrading NodeJS..." --time --weight=2
# #================================================= ynh_install_nodejs --nodejs_version=$nodejs_version
# # UPGRADE DEPENDENCIES
# #================================================= #=================================================
# ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 # NODEJS Version
#=================================================
ynh_use_nodejs
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
# ynh_install_app_dependencies $pkg_dependencies # ynh_install_app_dependencies $pkg_dependencies
# #================================================= #=================================================
# # PHP-FPM CONFIGURATION # SPECIFIC UPGRADE
# #================================================= #=================================================
# ynh_script_progression --message="Upgrading PHP-FPM configuration..." --time --weight=1
# # Create a dedicated PHP-FPM config ynh_script_progression --message="Upgrading Uptime Kuma dependencies..." --time --weight=7
# ynh_add_fpm_config cd $final_path && ynh_exec_warn_less $ynh_npm install
# #=================================================
# # SPECIFIC UPGRADE
# #=================================================
# # ...
# #=================================================
# #================================================= # #=================================================
# # UPDATE A CONFIG FILE # # UPDATE A CONFIG FILE
@ -188,37 +174,37 @@
# ### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/some_config_file" # ### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/some_config_file"
# ### ynh_store_file_checksum --file="$final_path/some_config_file" # ### ynh_store_file_checksum --file="$final_path/some_config_file"
# #================================================= #=================================================
# # SETUP SYSTEMD # SETUP SYSTEMD
# #================================================= #=================================================
# ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1 ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1
# # Create a dedicated systemd config # Create a dedicated systemd config
# ynh_add_systemd_config ynh_add_systemd_config
# #================================================= #=================================================
# # GENERIC FINALIZATION # GENERIC FINALIZATION
# #================================================= #=================================================
# # SETUP LOGROTATE # SETUP LOGROTATE
# #================================================= #=================================================
# ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1 ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
# # Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
# ynh_use_logrotate --non-append ynh_use_logrotate --non-append
# #================================================= #=================================================
# # INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
# #================================================= #=================================================
# ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1
# yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log" yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log"
# #================================================= #=================================================
# # START SYSTEMD SERVICE # START SYSTEMD SERVICE
# #================================================= #=================================================
# ynh_script_progression --message="Starting a systemd service..." --time --weight=1 ynh_script_progression --message="Starting a systemd service..." --time --weight=1
# ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
# #================================================= # #=================================================
# # UPGRADE FAIL2BAN # # UPGRADE FAIL2BAN
@ -228,15 +214,15 @@
# # Create a dedicated Fail2Ban config # # Create a dedicated Fail2Ban config
# ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" # ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
# #================================================= #=================================================
# # RELOAD NGINX # RELOAD NGINX
# #================================================= #=================================================
# ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1 ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1
# ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name=nginx --action=reload
# #================================================= #=================================================
# # END OF SCRIPT # END OF SCRIPT
# #================================================= #=================================================
# ynh_script_progression --message="Upgrade of $app completed" --time --last ynh_script_progression --message="Upgrade of $app completed" --time --last