1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/loki_ynh.git synced 2024-09-03 19:36:16 +02:00

Update manifestv2

This commit is contained in:
Salamandar 2024-01-30 00:34:13 +01:00
parent 3576bbd70f
commit 8b8df19a1a
5 changed files with 42 additions and 281 deletions

View file

@ -10,26 +10,6 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
#REMOVEME? ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
#REMOVEME? ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
#REMOVEME? ynh_print_info --message="Loading installation settings..."
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
@ -42,26 +22,20 @@ ynh_print_info --message="Declaring files to be backed up..."
ynh_backup --src_path="$install_dir"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/$app"
#=================================================
# BACKUP LOGROTATE
# SYSTEM CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/systemd/system/$app-promtail.service"
#=================================================
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="/etc/$app"
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -19,15 +19,11 @@ ynh_setup_source --dest_dir="$install_dir" --source_id="promtail"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
chown -R "$app:www-data" "$install_dir"
mkdir -p "/etc/$app/loki.d"
chmod 700 "/etc/$app/loki.d"
chown "$app:www-data" "/etc/$app/loki.d"
mkdir -p "/etc/$app/promtail.d"
chmod 700 "/etc/$app/promtail.d"
chown "$app:www-data" "/etc/$app/promtail.d"
mkdir -p "/etc/$app/loki.d" "/etc/$app/promtail.d"
chmod 700 "/etc/$app"
chown -R "$app:www-data" "/etc/$app"
#=================================================
# ADD A CONFIGURATION

View file

@ -10,98 +10,25 @@ source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? http_port=$(ynh_app_setting_get --app=$app --key=http_port)
#REMOVEME? grpc_port=$(ynh_app_setting_get --app=$app --key=grpc_port)
#REMOVEME? promtail_port=$(ynh_app_setting_get --app=$app --key=promtail_port)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --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=1
yunohost service remove $app
yunohost service remove $app-promtail
if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then
yunohost service remove "$app"
yunohost service remove "$app-promtail"
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
# Remove the dedicated systemd config
ynh_remove_systemd_config
ynh_remove_systemd_config --service="$app-promtail"
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# REMOVE APP MAIN DIR
#=================================================
#REMOVEME? ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely
#REMOVEME? ynh_secure_remove --file="$install_dir"
#=================================================
# REMOVE CONFIGURATION
#=================================================
# Remove the data directory if --purge option is used
if [ "${YNH_APP_PURGE:-0}" -eq 1 ]
then
ynh_script_progression --message="Removing app data directory..." --weight=1
ynh_secure_remove --file="/etc/$app"
fi
#=================================================
# REMOVE DEPENDENCIES
#=================================================
#REMOVEME? ynh_script_progression --message="Removing dependencies..." --weight=1
# Remove metapackage and its dependencies
#REMOVEME? ynh_remove_app_dependencies
#=================================================
# CLOSE PORTS
#=================================================
ynh_script_progression --message="Closing ports..." --weight=1
for port in $http_port $grpc_port $promtail_port
do
if yunohost firewall list | grep -q "\- $port$"
then
ynh_print_info --message="Closing port $port..." --weight=1
ynh_exec_warn_less yunohost firewall disallow TCP $port
fi
done
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
#REMOVEME? ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user
#REMOVEME? ynh_system_user_delete --username=$app
ynh_secure_remove --file="/etc/$app"
#=================================================
# END OF SCRIPT

View file

@ -10,45 +10,6 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
#REMOVEME? ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
#REMOVEME? ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
arch=$YNH_ARCH
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." --weight=1
#REMOVEME? test ! -d $install_dir \
|| ynh_die --message="There is already a directory: $install_dir "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
@ -58,22 +19,11 @@ ynh_restore_file --origin_path="$install_dir"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=1
# Define and install dependencies
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
chown -R "$app:www-data" "$install_dir"
#=================================================
# RESTORE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the configuration files..." --weight=1
ynh_restore_file --origin_path="/etc/$app"
@ -84,33 +34,22 @@ ynh_restore_file --origin_path="/etc/$app"
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
systemctl enable "$app.service" --quiet
yunohost service add "$app" --description="Loki daemon" --log="/var/log/$app/loki.log"
systemctl enable "$app-promtail.service" --quiet
ynh_restore_file --origin_path="/etc/systemd/system/$app-promtail.service"
systemctl enable $app-promtail.service --quiet
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
yunohost service add "$app-promtail" --description="Promtail daemon" --log="/var/log/$app/promtail.log"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Loki daemon" --log="/var/log/$app/loki.log"
yunohost service add $app-promtail --description="Promtail daemon" --log="/var/log/$app/promtail.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/loki.log"
ynh_systemd_action --service_name=$app-promtail --action="start" --log_path="/var/log/$app/promtail.log"
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/loki.log"
ynh_systemd_action --service_name="$app-promtail" --action="start" --log_path="/var/log/$app/promtail.log"
#=================================================
# END OF SCRIPT

View file

@ -9,39 +9,6 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
arch=$YNH_ARCH
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#REMOVEME? http_port=$(ynh_app_setting_get --app=$app --key=http_port)
#REMOVEME? grpc_port=$(ynh_app_setting_get --app=$app --key=grpc_port)
#REMOVEME? promtail_port=$(ynh_app_setting_get --app=$app --key=promtail_port)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# Backup the current version of the app
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
# Restore it if the upgrade fails
#REMOVEME? ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
#REMOVEME? ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
@ -49,54 +16,25 @@ upgrade_type=$(ynh_check_app_version_changed)
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# CREATE DEDICATED USER
#=================================================
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name="$app-promtail" --action="stop" --log_path="/var/log/$app/promtail.log"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..." --weight=1
if [ "$upgrade_type" == "UPGRADE_APP" ]
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="$install_dir" --source_id="loki-$YNH_ARCH"
ynh_setup_source --dest_dir="$install_dir" --source_id="promtail-$YNH_ARCH"
fi
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir" --source_id="loki" --full_replace=1
ynh_setup_source --dest_dir="$install_dir" --source_id="promtail"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
chown -R "$app:www-data" "$install_dir"
mkdir -p "/etc/$app/loki.d"
chmod 700 "/etc/$app/loki.d"
chown $app:www-data "/etc/$app/loki.d"
mkdir -p "/etc/$app/promtail.d"
chmod 700 "/etc/$app/promtail.d"
chown $app:www-data "/etc/$app/promtail.d"
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SPECIFIC UPGRADE
#=================================================
# ...
#=================================================
mkdir -p "/etc/$app/loki.d" "/etc/$app/promtail.d"
chmod 700 "/etc/$app"
chown -R "$app:www-data" "/etc/$app"
#=================================================
# UPDATE A CONFIG FILE
@ -109,7 +47,7 @@ ynh_add_config --template="loki-default.yaml" --destination="/etc/$app/loki-defa
# You may need to use chmod 600 instead of 400,
# for example if the app is expected to be able to modify its own config
chmod 400 "/etc/$app/loki-default.yaml"
chown $app:www-data "/etc/$app/loki-default.yaml"
chown "$app:www-data" "/etc/$app/loki-default.yaml"
ynh_add_config --template="promtail-default.yaml" --destination="/etc/$app/promtail-default.yaml"
@ -117,42 +55,29 @@ ynh_add_config --template="promtail-default.yaml" --destination="/etc/$app/promt
# You may need to use chmod 600 instead of 400,
# for example if the app is expected to be able to modify its own config
chmod 400 "/etc/$app/promtail-default.yaml"
chown $app:www-data "/etc/$app/promtail-default.yaml"
chown "$app:www-data" "/etc/$app/promtail-default.yaml"
#=================================================
# 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
# Create a dedicated systemd config
ynh_add_systemd_config --template="loki.service"
ynh_add_systemd_config --template="promtail.service" --service="$app-promtail"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
yunohost service add "$app" --description="Loki daemon" --log="/var/log/$app/loki.log"
yunohost service add "$app-promtail" --description="Promtail daemon" --log="/var/log/$app/promtail.log"
# 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..." --weight=1
yunohost service add $app --description="Loki daemon" --log="/var/log/$app/loki.log"
yunohost service add $app-promtail --description="Promtail daemon" --log="/var/log/$app/promtail.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/loki.log"
ynh_systemd_action --service_name=$app-promtail --action="start" --log_path="/var/log/$app/promtail.log"
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/loki.log"
ynh_systemd_action --service_name="$app-promtail" --action="start" --log_path="/var/log/$app/promtail.log"
#=================================================
# END OF SCRIPT