1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/loki_ynh.git synced 2024-09-03 19:36:16 +02:00
This commit is contained in:
YunoHost Bot 2024-08-31 13:21:23 +02:00 committed by GitHub
commit 7bd6c2fc41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 75 additions and 138 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
*~ *~
*.sw[op] *.sw[op]
.DS_Store

View file

@ -19,7 +19,8 @@ code = "https://github.com/grafana/loki"
cpe = "cpe:2.3:a:grafana:loki" cpe = "cpe:2.3:a:grafana:loki"
[integration] [integration]
yunohost = ">= 11.2" yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = ["amd64", "armhf", "arm64"] architectures = ["amd64", "armhf", "arm64"]
multi_instance = true multi_instance = true

View file

@ -1,19 +1,7 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# COMMON VARIABLES # COMMON VARIABLES AND CUSTOM HELPERS
#================================================= #=================================================
# PHP APP SPECIFIC # PHP APP SPECIFIC
#================================================= #=================================================
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -1,43 +1,34 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= ynh_print_info "Declaring files to be backed up..."
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_backup --src_path="$install_dir" ynh_backup "$install_dir"
#================================================= #=================================================
# SYSTEM CONFIGURATION # SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup "/etc/logrotate.d/$app"
ynh_backup --src_path="/etc/systemd/system/$app.service" ynh_backup "/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/systemd/system/$app-promtail.service" ynh_backup "/etc/systemd/system/$app-promtail.service"
#================================================= #=================================================
# BACKUP VARIOUS FILES # BACKUP VARIOUS FILES
#================================================= #=================================================
ynh_backup --src_path="/etc/$app" ynh_backup "/etc/$app"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,18 +1,12 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..." --weight=1 ynh_script_progression "Setting up source files..."
ynh_setup_source --dest_dir="$install_dir" --source_id="loki" ynh_setup_source --dest_dir="$install_dir" --source_id="loki"
ynh_setup_source --dest_dir="$install_dir" --source_id="promtail" ynh_setup_source --dest_dir="$install_dir" --source_id="promtail"
@ -21,10 +15,9 @@ ynh_setup_source --dest_dir="$install_dir" --source_id="promtail"
mv "$install_dir"/loki-linux-* "$install_dir"/loki mv "$install_dir"/loki-linux-* "$install_dir"/loki
mv "$install_dir"/promtail-linux-* "$install_dir"/promtail mv "$install_dir"/promtail-linux-* "$install_dir"/promtail
chmod 750 "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
mkdir -p "/etc/$app/loki.d" "/etc/$app/promtail.d" mkdir -p "/etc/$app/loki.d" "/etc/$app/promtail.d"
chmod 700 "/etc/$app" chmod 700 "/etc/$app"
chown -R "$app:www-data" "/etc/$app" chown -R "$app:www-data" "/etc/$app"
@ -32,48 +25,48 @@ chown -R "$app:www-data" "/etc/$app"
#================================================= #=================================================
# ADD A CONFIGURATION # ADD A CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1 ynh_script_progression "Adding $app's configuration..."
ynh_add_config --template="loki-default.yaml" --destination="/etc/$app/loki-default.yaml" ynh_config_add --template="loki-default.yaml" --destination="/etc/$app/loki-default.yaml"
# FIXME: this should be handled by the core in the future # FIXME: this should be handled by the core in the future
# You may need to use chmod 600 instead of 400, # 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 # for example if the app is expected to be able to modify its own config
chmod 400 "/etc/$app/loki-default.yaml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "/etc/$app/loki-default.yaml"
chown "$app:www-data" "/etc/$app/loki-default.yaml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:www-data" "/etc/$app/loki-default.yaml"
ynh_add_config --template="promtail-default.yaml" --destination="/etc/$app/promtail-default.yaml" ynh_config_add --template="promtail-default.yaml" --destination="/etc/$app/promtail-default.yaml"
# FIXME: this should be handled by the core in the future # FIXME: this should be handled by the core in the future
# You may need to use chmod 600 instead of 400, # 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 # for example if the app is expected to be able to modify its own config
chmod 400 "/etc/$app/promtail-default.yaml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "/etc/$app/promtail-default.yaml"
chown "$app:www-data" "/etc/$app/promtail-default.yaml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:www-data" "/etc/$app/promtail-default.yaml"
#================================================= #=================================================
# SYSTEM CONFIGURATION # SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 ynh_script_progression "Adding system configurations related to $app..."
ynh_add_systemd_config --template="loki.service" ynh_config_add_systemd --template="loki.service"
ynh_add_systemd_config --template="promtail.service" --service="$app-promtail" ynh_config_add_systemd --template="promtail.service" --service="$app-promtail"
yunohost service add "$app" --description="Loki daemon" --log="/var/log/$app/loki.log" 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" yunohost service add "$app-promtail" --description="Promtail daemon" --log="/var/log/$app/promtail.log"
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate ynh_config_add_logrotate
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/loki.log" --line_match="Loki started" ynh_systemctl --service="$app" --action="start" --log_path="/var/log/$app/loki.log" --wait_until="Loki started"
ynh_systemd_action --service_name="$app-promtail" --action="start" --log_path="/var/log/$app/promtail.log" --line_match="server listening on addresses" ynh_systemctl --service="$app-promtail" --action="start" --log_path="/var/log/$app/promtail.log" --wait_until="server listening on addresses"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of $app completed" --last ynh_script_progression "Installation of $app completed"

View file

@ -1,37 +1,31 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# REMOVE SYSTEM CONFIGURATIONS # REMOVE SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 ynh_script_progression "Removing system configurations related to $app..."
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) # 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 if ynh_hide_warnings yunohost service status "$app" >/dev/null; then
yunohost service remove "$app" yunohost service remove "$app"
yunohost service remove "$app-promtail" yunohost service remove "$app-promtail"
fi fi
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_remove_systemd_config ynh_config_remove_systemd
ynh_remove_systemd_config --service="$app-promtail" ynh_config_remove_systemd"$app-promtail"
#================================================= #=================================================
# REMOVE CONFIGURATION # REMOVE CONFIGURATION
#================================================= #=================================================
ynh_secure_remove --file="/etc/$app" ynh_safe_rm "/etc/$app"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last ynh_script_progression "Removal of $app completed"

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -13,46 +7,45 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_script_progression "Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir" ynh_restore "$install_dir"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
#================================================= #=================================================
# RESTORE CONFIGURATION # RESTORE CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring the configuration files..." --weight=1 ynh_script_progression "Restoring the configuration files..."
ynh_restore_file --origin_path="/etc/$app" ynh_restore "/etc/$app"
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 ynh_script_progression "Restoring $app's systemd service..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore "/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" yunohost service add "$app" --description="Loki daemon" --log="/var/log/$app/loki.log"
ynh_restore_file --origin_path="/etc/systemd/system/$app-promtail.service" ynh_restore "/etc/systemd/system/$app-promtail.service"
systemctl enable "$app-promtail.service" --quiet systemctl enable "$app-promtail.service" --quiet
yunohost service add "$app-promtail" --description="Promtail daemon" --log="/var/log/$app/promtail.log" yunohost service add "$app-promtail" --description="Promtail daemon" --log="/var/log/$app/promtail.log"
ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_restore "/etc/logrotate.d/$app"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/loki.log" --line_match="Loki started" ynh_systemctl --service="$app" --action="start" --log_path="/var/log/$app/loki.log" --wait_until="Loki started"
ynh_systemd_action --service_name="$app-promtail" --action="start" --log_path="/var/log/$app/promtail.log" --line_match="server listening on addresses" ynh_systemctl --service="$app-promtail" --action="start" --log_path="/var/log/$app/promtail.log" --wait_until="server listening on addresses"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Restoration completed for $app" --last ynh_script_progression "Restoration completed for $app"

View file

@ -1,41 +1,33 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# STANDARD UPGRADE STEPS
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" ynh_systemctl --service="$app" --action="stop"
ynh_systemd_action --service_name="$app-promtail" --action="stop" --log_path="/var/log/$app/promtail.log"
ynh_systemctl --service="$app-promtail" --action="stop" --log_path="/var/log/$app/promtail.log"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Upgrading source files..." --weight=1 ynh_script_progression "Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src # 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="loki" --full_replace
ynh_setup_source --dest_dir="$install_dir" --source_id="promtail" ynh_setup_source --dest_dir="$install_dir" --source_id="promtail"
# Rename the binaries to remove arch # Rename the binaries to remove arch
mv "$install_dir"/loki-linux-* "$install_dir"/loki mv "$install_dir"/loki-linux-* "$install_dir"/loki
mv "$install_dir"/promtail-linux-* "$install_dir"/promtail mv "$install_dir"/promtail-linux-* "$install_dir"/promtail
chmod 750 "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
mkdir -p "/etc/$app/loki.d" "/etc/$app/promtail.d" mkdir -p "/etc/$app/loki.d" "/etc/$app/promtail.d"
chmod 700 "/etc/$app" chmod 700 "/etc/$app"
chown -R "$app:www-data" "/etc/$app" chown -R "$app:www-data" "/etc/$app"
@ -43,48 +35,48 @@ chown -R "$app:www-data" "/etc/$app"
#================================================= #=================================================
# UPDATE A CONFIG FILE # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1 ynh_script_progression "Updating configuration..."
ynh_add_config --template="loki-default.yaml" --destination="/etc/$app/loki-default.yaml" ynh_config_add --template="loki-default.yaml" --destination="/etc/$app/loki-default.yaml"
# FIXME: this should be handled by the core in the future # FIXME: this should be handled by the core in the future
# You may need to use chmod 600 instead of 400, # 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 # for example if the app is expected to be able to modify its own config
chmod 400 "/etc/$app/loki-default.yaml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "/etc/$app/loki-default.yaml"
chown "$app:www-data" "/etc/$app/loki-default.yaml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:www-data" "/etc/$app/loki-default.yaml"
ynh_add_config --template="promtail-default.yaml" --destination="/etc/$app/promtail-default.yaml" ynh_config_add --template="promtail-default.yaml" --destination="/etc/$app/promtail-default.yaml"
# FIXME: this should be handled by the core in the future # FIXME: this should be handled by the core in the future
# You may need to use chmod 600 instead of 400, # 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 # for example if the app is expected to be able to modify its own config
chmod 400 "/etc/$app/promtail-default.yaml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "/etc/$app/promtail-default.yaml"
chown "$app:www-data" "/etc/$app/promtail-default.yaml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:www-data" "/etc/$app/promtail-default.yaml"
#================================================= #=================================================
# REAPPLY SYSTEM CONFIGURATIONS # REAPPLY SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 ynh_script_progression "Upgrading system configurations related to $app..."
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config --template="loki.service" ynh_config_add_systemd --template="loki.service"
ynh_add_systemd_config --template="promtail.service" --service="$app-promtail" ynh_config_add_systemd --template="promtail.service" --service="$app-promtail"
yunohost service add "$app" --description="Loki daemon" --log="/var/log/$app/loki.log" 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" yunohost service add "$app-promtail" --description="Promtail daemon" --log="/var/log/$app/promtail.log"
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append ynh_config_add_logrotate
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/loki.log" --line_match="Loki started" ynh_systemctl --service="$app" --action="start" --log_path="/var/log/$app/loki.log" --wait_until="Loki started"
ynh_systemd_action --service_name="$app-promtail" --action="start" --log_path="/var/log/$app/promtail.log" --line_match="server listening on addresses" ynh_systemctl --service="$app-promtail" --action="start" --log_path="/var/log/$app/promtail.log" --wait_until="server listening on addresses"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression "Upgrade of $app completed"

View file

@ -1,2 +0,0 @@
*~
*.sw[op]

View file

@ -1,14 +0,0 @@
#!/bin/bash
shopt -s nullglob
file_list=($@)
{
for file in "${file_list[@]}"
do
/usr/bin/python3 -c "import yaml, json; print(json.dumps(yaml.safe_load(open('$file')), default=str))"
done
} \
| /usr/bin/jq --slurp 'reduce .[] as $item ({}; . * $item)' \
| /usr/bin/python3 -c "import yaml, json; print(yaml.dump(json.load(open('/dev/stdin'))))"