mirror of
https://github.com/YunoHost-Apps/yunomonitor_ynh.git
synced 2024-09-03 17:46:11 +02:00
manifestv2
This commit is contained in:
parent
64c9fef98b
commit
d6fb14fae5
14 changed files with 189 additions and 410 deletions
|
@ -1,20 +0,0 @@
|
|||
;; Test complet
|
||||
; Manifest
|
||||
monitored_servers="remote_domain.tld,remote_domain2.tld"
|
||||
monitoring_servers=""
|
||||
mails="john@example.com"
|
||||
sms_api=""
|
||||
; Checks
|
||||
pkg_linter=1
|
||||
setup_sub_dir=0
|
||||
setup_root=0
|
||||
setup_nourl=1
|
||||
setup_private=0
|
||||
setup_public=0
|
||||
upgrade=1
|
||||
# 1.1.0~ynh2
|
||||
upgrade=1 from_commit=4feb4a78181518956e7d230a2ab67d96992f8563
|
||||
backup_restore=1
|
||||
multi_instance=0
|
||||
port_already_use=0
|
||||
change_url=0
|
|
@ -1,7 +0,0 @@
|
|||
SOURCE_URL=https://github.com/zamentur/yunomonitor/archive/0a2c295485dbda9da3b97353e094ef414c939609.tar.gz
|
||||
SOURCE_SUM=e9c63885c5158771a00ae892967a0f7d1f3f538f26d124f8f096bb7b8ff3113a
|
||||
SOURCE_SUM_PRG=sha256sum
|
||||
SOURCE_FORMAT=tar.gz
|
||||
SOURCE_IN_SUBDIR=true
|
||||
SOURCE_FILENAME=yunomonitor-1-1-0.tar.gz
|
||||
SOURCE_EXTRACT=true
|
|
@ -1,5 +1,5 @@
|
|||
location ^~ '/.well-known/yunomonitor/' {
|
||||
|
||||
default_type "text/plain";
|
||||
alias __FINALPATH__/well-known/;
|
||||
alias __INSTALL_DIR__/well-known/;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ After=network.target
|
|||
Type=oneshot
|
||||
User=__APP__
|
||||
Group=__APP__
|
||||
WorkingDirectory=__FINALPATH__
|
||||
ExecStart=__FINALPATH__/yunomonitor.py -c __FINALPATH__/conf/__APP__.yml
|
||||
WorkingDirectory=__INSTALL_DIR__
|
||||
ExecStart=__INSTALL_DIR__/yunomonitor.py -c __INSTALL_DIR__/conf/__APP__.yml
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
{
|
||||
"name": "YunoMonitor",
|
||||
"id": "yunomonitor",
|
||||
"packaging_format": 1,
|
||||
"description": {
|
||||
"en": "Home made tool to monitor automatically your servers",
|
||||
"fr": "Outil pour surveiller automatiquement vos serveurs"
|
||||
},
|
||||
"version": "1.1.0~ynh3",
|
||||
"url": "https://github.com/zamentur/yunomonitor",
|
||||
"upstream": {
|
||||
"license": "AGPL-3.0",
|
||||
"website": "https://github.com/zamentur/yunomonitor",
|
||||
"admindoc": "https://github.com/zamentur/yunomonitor/blob/master/README.md",
|
||||
"code": "https://github.com/zamentur/yunomonitor"
|
||||
},
|
||||
"license": "AGPL-3.0",
|
||||
"maintainer": {
|
||||
"name": "ljf",
|
||||
"email": "ljf+@reflexlibre.net",
|
||||
"url": "https://reflexlibre.net"
|
||||
},
|
||||
"requirements": {
|
||||
"yunohost": ">= 4.3.0"
|
||||
},
|
||||
"multi_instance": false,
|
||||
"services": [
|
||||
"nginx"
|
||||
],
|
||||
"arguments": {
|
||||
"install": [
|
||||
{
|
||||
"name": "monitored_servers",
|
||||
"type": "string",
|
||||
"ask": {
|
||||
"en": "List all servers you want to monitor with this server (separated by comma)"
|
||||
},
|
||||
"help": {
|
||||
"en": "You need to install yunomonitor on those servers or add manually a custom configuration file for each server to monitor"
|
||||
},
|
||||
"example": "example.com,example2.com",
|
||||
"default": "localhost"
|
||||
},
|
||||
{
|
||||
"name": "monitoring_servers",
|
||||
"type": "string",
|
||||
"ask": {
|
||||
"en": "List all monitoring servers that monitored this server (separated by comma)"
|
||||
},
|
||||
"example": "example.com,example2.com",
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"name": "mails",
|
||||
"type": "string",
|
||||
"ask": {
|
||||
"en": "Mails to which send alerts about servers monitored by this server (separated by comma)"
|
||||
},
|
||||
"example": "john@example.com,jane@example.com",
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"name": "sms_api",
|
||||
"type": "string",
|
||||
"ask": {
|
||||
"en": "List here an SMS URL to use to send alerts by SMS (e.g. the internet provider 'free' offers some API for that)"
|
||||
},
|
||||
"example": "https://smsapi.free-mobile.fr/sendmsg?user=USERID&pass=PASSWORD&msg=",
|
||||
"optional": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
80
manifest.toml
Normal file
80
manifest.toml
Normal file
|
@ -0,0 +1,80 @@
|
|||
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json
|
||||
|
||||
packaging_format = 2
|
||||
|
||||
id = "yunomonitor"
|
||||
name = "YunoMonitor"
|
||||
description.en = "Home made tool to monitor automatically your servers"
|
||||
description.fr = "Outil pour surveiller automatiquement vos serveurs"
|
||||
|
||||
version = "1.1.0~ynh3"
|
||||
|
||||
maintainers = ["ljf"]
|
||||
|
||||
[upstream]
|
||||
license = "AGPL-3.0"
|
||||
code = "https://github.com/zamentur/yunomonitor"
|
||||
admindoc = "https://github.com/zamentur/yunomonitor/blob/master/README.md"
|
||||
fund = "https://donate.yunohost.org/"
|
||||
|
||||
[integration]
|
||||
yunohost = ">= 4.3.0"
|
||||
architectures = "all"
|
||||
multi_instance = false
|
||||
ldap = "not_relevant"
|
||||
sso = "not_relevant"
|
||||
disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ...
|
||||
ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
|
||||
ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
|
||||
|
||||
[install]
|
||||
[install.monitored_servers]
|
||||
ask.en = "List all servers you want to monitor with this server (separated by comma)"
|
||||
help.en = "You need to install yunomonitor on those servers or add manually a custom configuration file for each server to monitor"
|
||||
type = "string"
|
||||
example = "example.com,example2.com"
|
||||
default = "localhost"
|
||||
|
||||
[install.monitoring_servers]
|
||||
ask.en = "List all monitoring servers that monitored this server (separated by comma)"
|
||||
type = "string"
|
||||
example = "example.com,example2.com"
|
||||
optional = true
|
||||
|
||||
[install.mails]
|
||||
ask.en = "Mails to which send alerts about servers monitored by this server (separated by comma)"
|
||||
type = "string"
|
||||
example = "john@example.com,jane@example.com"
|
||||
optional = true
|
||||
|
||||
[install.sms_api]
|
||||
ask.en = "List here an SMS URL to use to send alerts by SMS (e.g. the internet provider 'free' offers some API for that)"
|
||||
type = "string"
|
||||
example = "https://smsapi.free-mobile.fr/sendmsg?user=USERID&pass=PASSWORD&msg="
|
||||
optional = true
|
||||
|
||||
[resources]
|
||||
[resources.sources.main]
|
||||
url = "https://github.com/zamentur/yunomonitor/archive/0a2c295485dbda9da3b97353e094ef414c939609.tar.gz"
|
||||
sha256 = "e9c63885c5158771a00ae892967a0f7d1f3f538f26d124f8f096bb7b8ff3113a"
|
||||
autoupdate.strategy = "latest_github_commit"
|
||||
|
||||
[resources.system_user]
|
||||
|
||||
[resources.install_dir]
|
||||
|
||||
[resources.permissions]
|
||||
|
||||
[resources.apt]
|
||||
packages = [
|
||||
"python3-dbus",
|
||||
"python3-pip",
|
||||
"python3-cryptography",
|
||||
"python3-paramiko",
|
||||
"python3-yaml",
|
||||
"python3-dnspython",
|
||||
"python3-requests-toolbelt",
|
||||
"python3-spf",
|
||||
"whois",
|
||||
"smartmontools",
|
||||
]
|
|
@ -4,13 +4,28 @@
|
|||
# COMMON VARIABLES
|
||||
#=================================================
|
||||
|
||||
# dependencies used by the app
|
||||
pkg_dependencies="python3-dbus python3-cryptography python3-paramiko python3-yaml python3-dnspython python3-requests-toolbelt python3-spf whois smartmontools"
|
||||
|
||||
|
||||
#=================================================
|
||||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
||||
_yunomonitor_add_nginx_config() {
|
||||
# Create a dedicated nginx config
|
||||
# Note: i don't use the helper because i need this file to be named "000-"
|
||||
finalnginxconf="/etc/nginx/conf.d/$domain.d/000-$app.conf"
|
||||
ynh_backup_if_checksum_is_different --file="$finalnginxconf"
|
||||
cp ../conf/nginx.conf "$finalnginxconf"
|
||||
ynh_replace_string --match_string="__INSTALL_DIR__" --replace_string="$install_dir" --target_file="$finalnginxconf"
|
||||
ynh_store_file_checksum --file="$finalnginxconf"
|
||||
}
|
||||
|
||||
_yunomonitor_remove_nginx_config() {
|
||||
finalnginxconf="/etc/nginx/conf.d/$domain.d/000-$app.conf"
|
||||
ynh_secure_remove --file="$finalnginxconf"
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# EXPERIMENTAL HELPERS
|
||||
#=================================================
|
||||
|
@ -20,26 +35,13 @@ ynh_export () {
|
|||
for var in $@;
|
||||
do
|
||||
ynh_arg=$(echo $var | awk '{print toupper($0)}')
|
||||
if [ "$var" == "path_url" ]; then
|
||||
if [ "$var" == "path" ]; then
|
||||
ynh_arg="PATH"
|
||||
fi
|
||||
ynh_arg="YNH_APP_ARG_$ynh_arg"
|
||||
export $var="${!ynh_arg}"
|
||||
done
|
||||
}
|
||||
# Save listed var in YunoHost app settings
|
||||
# usage: ynh_save_args VARNAME1 [VARNAME2 [...]]
|
||||
|
||||
ynh_save_args () {
|
||||
for var in $@;
|
||||
do
|
||||
local setting_var="$var"
|
||||
if [ "$var" == "path_url" ]; then
|
||||
setting_var="path"
|
||||
fi
|
||||
ynh_app_setting_set "$app" "$setting_var" "${!var}"
|
||||
done
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# FUTURE OFFICIAL HELPERS
|
||||
|
|
|
@ -10,23 +10,6 @@
|
|||
source ../settings/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_print_info --message="Loading installation settings..."
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
|
||||
#=================================================
|
||||
# DECLARE DATA AND CONF FILES TO BACKUP
|
||||
#=================================================
|
||||
|
@ -36,7 +19,7 @@ ynh_print_info --message="Declaring files to be backed up..."
|
|||
# BACKUP THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
ynh_backup --src_path="$final_path"
|
||||
ynh_backup --src_path="$install_dir"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
|
|
118
scripts/install
118
scripts/install
|
@ -10,83 +10,36 @@ source _common.sh
|
|||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
# STORE SETTINGS
|
||||
#=================================================
|
||||
|
||||
ynh_clean_setup () {
|
||||
true
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
domain=$(yunohost domain list --json | jq -r '.["main"]')
|
||||
path=/.well-known/yunomonitor/
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||
#=================================================
|
||||
ynh_app_setting_set --app="$app" --key="domain" --value="$domain"
|
||||
ynh_app_setting_set --app="$app" --key="path" --value="$path"
|
||||
|
||||
export domain=$(cat /etc/yunohost/current_host)
|
||||
export path_url=/.well-known/yunomonitor/
|
||||
# FIXME: required?
|
||||
ynh_export monitored_servers monitoring_servers mails sms_api
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
||||
|
||||
final_path=/opt/$app
|
||||
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
||||
|
||||
#=================================================
|
||||
# STORE SETTINGS FROM MANIFEST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Storing installation settings..." --weight=1
|
||||
|
||||
ynh_save_args domain path_url monitored_servers monitoring_servers mails sms_api
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing dependencies..." --weight=1
|
||||
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring system user..." --weight=1
|
||||
|
||||
# Create a system user
|
||||
ynh_system_user_create --username=$app --home_dir="$final_path"
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Setting up source files..." --weight=1
|
||||
|
||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source --dest_dir="$final_path"
|
||||
ynh_setup_source --dest_dir="$install_dir"
|
||||
|
||||
chmod 750 "$final_path"
|
||||
chmod -R o-rwx "$final_path"
|
||||
chown -R $app:www-data "$final_path"
|
||||
chmod 750 "$install_dir"
|
||||
chmod -R o-rwx "$install_dir"
|
||||
chown -R "$app:www-data" "$install_dir"
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
||||
|
||||
# Create a dedicated nginx config
|
||||
# Note: i don't use the helper because i need this file to be named "000-"
|
||||
finalnginxconf="/etc/nginx/conf.d/$domain.d/000-$app.conf"
|
||||
ynh_backup_if_checksum_is_different --file="$finalnginxconf"
|
||||
cp ../conf/nginx.conf "$finalnginxconf"
|
||||
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finalnginxconf"
|
||||
ynh_store_file_checksum --file="$finalnginxconf"
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
_yunomonitor_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC SETUP
|
||||
|
@ -95,8 +48,8 @@ ynh_systemd_action --service_name=nginx --action=reload
|
|||
#=================================================
|
||||
ynh_script_progression --message="Building Yunomonitor..."
|
||||
|
||||
pushd "$final_path"
|
||||
pip3 install pycryptodome
|
||||
pushd "$install_dir"
|
||||
python3 -m pip install pycryptodome
|
||||
popd
|
||||
|
||||
#=================================================
|
||||
|
@ -105,50 +58,41 @@ popd
|
|||
ynh_script_progression --message="Configuring a systemd service..."
|
||||
|
||||
ynh_add_systemd_config
|
||||
cp ../conf/systemd.timer "/etc/systemd/system/$app.timer"
|
||||
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/systemd/system/$app.timer"
|
||||
ynh_add_config --template="systemd.timer" --destination="/etc/systemd/system/$app.timer"
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable $app.timer --quiet
|
||||
systemctl start $app.timer
|
||||
systemctl enable "$app.timer" --quiet
|
||||
systemctl start "$app.timer"
|
||||
|
||||
#=================================================
|
||||
# ADD A CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Adding a configuration file..."
|
||||
|
||||
echo "mails: [$mails]" > $final_path/conf/$app.yml
|
||||
echo "sms_apis: [$sms_api]" >> $final_path/conf/$app.yml
|
||||
echo "monitored_servers: [$monitored_servers]" >> $final_path/conf/$app.yml
|
||||
echo "monitoring_servers: [$monitoring_servers]" >> $final_path/conf/$app.yml
|
||||
echo "cachet_apis: []" >> $final_path/conf/$app.yml
|
||||
sed -i 's/,/","/g' $final_path/conf/$app.yml
|
||||
sed -i 's/\[/["/g' $final_path/conf/$app.yml
|
||||
sed -i 's/\]/"]/g' $final_path/conf/$app.yml
|
||||
sed -i 's/\[""\]/[]/g' $final_path/conf/$app.yml
|
||||
echo "mails: [$mails]" > $install_dir/conf/$app.yml
|
||||
echo "sms_apis: [$sms_api]" >> $install_dir/conf/$app.yml
|
||||
echo "monitored_servers: [$monitored_servers]" >> $install_dir/conf/$app.yml
|
||||
echo "monitoring_servers: [$monitoring_servers]" >> $install_dir/conf/$app.yml
|
||||
echo "cachet_apis: []" >> $install_dir/conf/$app.yml
|
||||
sed -i 's/,/","/g' $install_dir/conf/$app.yml
|
||||
sed -i 's/\[/["/g' $install_dir/conf/$app.yml
|
||||
sed -i 's/\]/"]/g' $install_dir/conf/$app.yml
|
||||
sed -i 's/\[""\]/[]/g' $install_dir/conf/$app.yml
|
||||
|
||||
# Calculate and store the config file checksum into the app settings
|
||||
ynh_store_file_checksum --file="$final_path/conf/$app.yml"
|
||||
ynh_store_file_checksum --file="$install_dir/conf/$app.yml"
|
||||
|
||||
#=================================================
|
||||
# INIT IGNORE FILE
|
||||
#=================================================
|
||||
|
||||
echo "method level server message target" > $final_path/conf/ignore_alert.csv
|
||||
echo "method level server message target" > "$install_dir/conf/ignore_alert.csv"
|
||||
|
||||
|
||||
# Set permissions to app files
|
||||
chmod u+x $final_path/yunomonitor.py
|
||||
chmod u+w $final_path/conf
|
||||
chmod u+w $final_path/well-known
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
chmod u+x "$install_dir/yunomonitor.py"
|
||||
chmod u+w "$install_dir/conf"
|
||||
chmod u+w "$install_dir/well-known"
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
|
|
|
@ -9,61 +9,30 @@
|
|||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
#=================================================
|
||||
# STOP AND REMOVE SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
|
||||
|
||||
# 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..." --weight=3
|
||||
yunohost service remove "$app"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# REMOVE SYSTEM CONFIGURATIONS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" --timeout=15
|
||||
|
||||
ynh_secure_remove --file="/etc/systemd/system/$app.timer"
|
||||
|
||||
# Remove the dedicated systemd config
|
||||
ynh_remove_systemd_config
|
||||
|
||||
#=================================================
|
||||
# REMOVE APP MAIN DIR
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing app main directory..." --weight=1
|
||||
|
||||
# Remove the app directory securely
|
||||
ynh_secure_remove --file="$final_path"
|
||||
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
|
||||
|
||||
# Remove the dedicated NGINX config
|
||||
ynh_remove_nginx_config
|
||||
|
||||
#=================================================
|
||||
# REMOVE DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing dependencies..." --weight=1
|
||||
|
||||
# Remove metapackage and its dependencies
|
||||
ynh_remove_app_dependencies
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# REMOVE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
|
||||
|
||||
# Delete a system user
|
||||
ynh_system_user_delete --username=$app
|
||||
_yunomonitor_remove_nginx_config
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
|
|
|
@ -10,41 +10,6 @@
|
|||
source ../settings/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#=================================================
|
||||
ynh_script_progression --message="Validating restoration parameters..." --weight=1
|
||||
|
||||
test ! -d $final_path \
|
||||
|| ynh_die --message="There is already a directory: $final_path "
|
||||
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
# RECREATE THE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
|
||||
|
||||
# Create the dedicated user (if not existing)
|
||||
ynh_system_user_create --username=$app --home_dir="$final_path"
|
||||
|
||||
#=================================================
|
||||
# RESTORE FILES
|
||||
#=================================================
|
||||
|
@ -57,30 +22,20 @@ ynh_restore
|
|||
#=================================================
|
||||
|
||||
# Restore permissions on app files
|
||||
chmod 750 "$final_path"
|
||||
chmod -R o-rwx "$final_path"
|
||||
chown -R $app:www-data "$final_path"
|
||||
chmod u+x $final_path/yunomonitor.py
|
||||
chmod u+w $final_path/conf
|
||||
chmod u+w $final_path/well-known
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC RESTORATION
|
||||
#=================================================
|
||||
# REINSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reinstalling dependencies..." --weight=1
|
||||
|
||||
# Define and install dependencies
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
chmod 750 "$install_dir"
|
||||
chmod -R o-rwx "$install_dir"
|
||||
chown -R $app:www-data "$install_dir"
|
||||
chmod u+x "$install_dir/yunomonitor.py"
|
||||
chmod u+w "$install_dir/conf"
|
||||
chmod u+w "$install_dir/well-known"
|
||||
|
||||
#=================================================
|
||||
# BUILD YUNOMONITOR
|
||||
#=================================================
|
||||
ynh_script_progression --message="Building Yunomonitor..."
|
||||
|
||||
pushd "$final_path"
|
||||
pip3 install pycryptodome
|
||||
pushd "$install_dir"
|
||||
python3 -m pip install pycryptodome
|
||||
popd
|
||||
|
||||
#=================================================
|
||||
|
@ -89,9 +44,9 @@ popd
|
|||
ynh_script_progression --message="Activating systemd timer..." --weight=1
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable $app.service --quiet
|
||||
systemctl enable $app.timer --quiet
|
||||
systemctl start $app.timer
|
||||
systemctl enable "$app.service" --quiet
|
||||
systemctl enable "$app.timer" --quiet
|
||||
systemctl start "$app.timer"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
|
|
102
scripts/upgrade
102
scripts/upgrade
|
@ -9,37 +9,8 @@
|
|||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
#=================================================
|
||||
# CHECK VERSION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Checking version..."
|
||||
|
||||
upgrade_type=$(ynh_check_app_version_changed)
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
|
||||
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
# Restore it if the upgrade fails
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# STANDARD UPGRADE STEPS
|
||||
#=================================================
|
||||
|
@ -47,18 +18,10 @@ ynh_abort_if_errors
|
|||
#=================================================
|
||||
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
||||
|
||||
if ! [ -f $final_path/conf/ignore_alert.csv ]; then
|
||||
echo "method level server message target" > $final_path/conf/ignore_alert.csv
|
||||
if ! [ -f $install_dir/conf/ignore_alert.csv ]; then
|
||||
echo "method level server message target" > $install_dir/conf/ignore_alert.csv
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
||||
|
||||
# Create a dedicated user (if not existing)
|
||||
ynh_system_user_create --username=$app --home_dir="$final_path"
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
@ -68,46 +31,23 @@ then
|
|||
ynh_script_progression --message="Upgrading source files..." --weight=1
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source --dest_dir="$final_path"
|
||||
ynh_setup_source --dest_dir="$install_dir"
|
||||
fi
|
||||
|
||||
chmod 750 "$final_path"
|
||||
chmod -R o-rwx "$final_path"
|
||||
chown -R $app:www-data "$final_path"
|
||||
chmod u+x $final_path/yunomonitor.py
|
||||
chmod u+w $final_path/conf
|
||||
chmod u+w $final_path/well-known
|
||||
chmod 750 "$install_dir"
|
||||
chmod -R o-rwx "$install_dir"
|
||||
chown -R $app:www-data "$install_dir"
|
||||
chmod u+x "$install_dir/yunomonitor.py"
|
||||
chmod u+w "$install_dir/conf"
|
||||
chmod u+w "$install_dir/well-known"
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
||||
|
||||
# Create a dedicated nginx config
|
||||
# Note: i don't use the helper because i need this file to be named "000-"
|
||||
finalnginxconf="/etc/nginx/conf.d/$domain.d/000-$app.conf"
|
||||
ynh_backup_if_checksum_is_different --file="$finalnginxconf"
|
||||
cp ../conf/nginx.conf "$finalnginxconf"
|
||||
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finalnginxconf"
|
||||
ynh_store_file_checksum --file="$finalnginxconf"
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# UPGRADE DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
||||
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
#=================================================
|
||||
# BUILD YUNOMONITOR
|
||||
#=================================================
|
||||
ynh_script_progression --message="Building Yunomonitor..."
|
||||
|
||||
pushd "$final_path"
|
||||
pip3 install pycryptodome
|
||||
pushd "$install_dir"
|
||||
python3 -m pip install pycryptodome
|
||||
popd
|
||||
|
||||
#=================================================
|
||||
|
@ -116,16 +56,17 @@ popd
|
|||
|
||||
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
|
||||
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
|
||||
ynh_backup_if_checksum_is_different --file="$final_path/conf/$app.yml"
|
||||
ynh_backup_if_checksum_is_different --file="$install_dir/conf/$app.yml"
|
||||
# Recalculate and store the checksum of the file for the next upgrade.
|
||||
ynh_store_file_checksum --file="$final_path/conf/$app.yml"
|
||||
ynh_store_file_checksum --file="$install_dir/conf/$app.yml"
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
# REAPPLY SYSTEM CONFIGURATIONS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
||||
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
||||
|
||||
_yunomonitor_add_nginx_config
|
||||
|
||||
# Create a dedicated systemd config
|
||||
ynh_add_systemd_config
|
||||
|
||||
#=================================================
|
||||
|
@ -133,14 +74,7 @@ ynh_add_systemd_config
|
|||
#=================================================
|
||||
ynh_script_progression --message="Reloading a systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="reload" --log_path="/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
ynh_systemd_action --service_name="$app" --action="reload" --log_path="/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
|
|
12
tests.toml
Normal file
12
tests.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json
|
||||
|
||||
test_format = 1.0
|
||||
|
||||
[default]
|
||||
|
||||
args.monitored_servers = "remote_domain.tld,remote_domain2.tld"
|
||||
args.monitoring_servers = ""
|
||||
args.mails = "john@example.com"
|
||||
args.sms_api = ""
|
||||
|
||||
test_upgrade_from.4feb4a78181518956e7d230a2ab67d96992f8563.name = "1.1.0~ynh2"
|
Loading…
Reference in a new issue