diff --git a/.gitignore b/.gitignore index 783a4ae..8f144f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ *.sw[op] +.DS_Store diff --git a/manifest.toml b/manifest.toml index a8e45f3..e2d466a 100644 --- a/manifest.toml +++ b/manifest.toml @@ -19,7 +19,8 @@ code = "https://github.com/grafana/loki" cpe = "cpe:2.3:a:grafana:loki" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = ["amd64", "armhf", "arm64"] multi_instance = true diff --git a/scripts/_common.sh b/scripts/_common.sh index 1e47ce7..253c6fe 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,19 +1,7 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= # PHP APP SPECIFIC #================================================= - -#================================================= -# PERSONAL HELPERS -#================================================= - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= diff --git a/scripts/backup b/scripts/backup index ad27826..08d345a 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,43 +1,34 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" #================================================= # 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 --src_path="/etc/systemd/system/$app-promtail.service" +ynh_backup "/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app-promtail.service" #================================================= # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/etc/$app" +ynh_backup "/etc/$app" #================================================= # 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)." diff --git a/scripts/install b/scripts/install index 3803663..f8bd330 100755 --- a/scripts/install +++ b/scripts/install @@ -1,18 +1,12 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # 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="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"/promtail-linux-* "$install_dir"/promtail -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" mkdir -p "/etc/$app/loki.d" "/etc/$app/promtail.d" chmod 700 "/etc/$app" chown -R "$app:www-data" "/etc/$app" @@ -32,48 +25,48 @@ chown -R "$app:www-data" "/etc/$app" #================================================= # 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 # 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" +#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" +#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 # 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" +#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" +#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 #================================================= -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_add_systemd_config --template="promtail.service" --service="$app-promtail" +ynh_config_add_systemd --template="loki.service" +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-promtail" --description="Promtail daemon" --log="/var/log/$app/promtail.log" # Use logrotate to manage application logfile(s) -ynh_use_logrotate +ynh_config_add_logrotate #================================================= # 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 -ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/loki.log" --line_match="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" --action="start" --log_path="/var/log/$app/loki.log" --wait_until="Loki started" +ynh_systemctl --service="$app-promtail" --action="start" --log_path="/var/log/$app/promtail.log" --wait_until="server listening on addresses" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 83ff7cc..d658111 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,37 +1,31 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # 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`) -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-promtail" fi # Remove the dedicated systemd config -ynh_remove_systemd_config -ynh_remove_systemd_config --service="$app-promtail" +ynh_config_remove_systemd +ynh_config_remove_systemd"$app-promtail" #================================================= # REMOVE CONFIGURATION #================================================= -ynh_secure_remove --file="/etc/$app" +ynh_safe_rm "/etc/$app" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 5ea9c2e..45f7178 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -13,46 +7,45 @@ source /usr/share/yunohost/helpers #================================================= # 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" - -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -R "$app:www-data" "$install_dir" +ynh_restore "$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 #================================================= -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 #================================================= -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 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 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 #================================================= -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_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" --action="start" --log_path="/var/log/$app/loki.log" --wait_until="Loki started" +ynh_systemctl --service="$app-promtail" --action="start" --log_path="/var/log/$app/promtail.log" --wait_until="server listening on addresses" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 32d593d..572b46d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,41 +1,33 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD UPGRADE STEPS #================================================= # 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_systemd_action --service_name="$app-promtail" --action="stop" --log_path="/var/log/$app/promtail.log" +ynh_systemctl --service="$app" --action="stop" + +ynh_systemctl --service="$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 +ynh_script_progression "Upgrading source files..." # 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" # Rename the binaries to remove arch mv "$install_dir"/loki-linux-* "$install_dir"/loki mv "$install_dir"/promtail-linux-* "$install_dir"/promtail -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" mkdir -p "/etc/$app/loki.d" "/etc/$app/promtail.d" chmod 700 "/etc/$app" chown -R "$app:www-data" "/etc/$app" @@ -43,48 +35,48 @@ chown -R "$app:www-data" "/etc/$app" #================================================= # 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 # 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" +#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" +#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 # 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" +#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" +#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 #================================================= -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 -ynh_add_systemd_config --template="loki.service" -ynh_add_systemd_config --template="promtail.service" --service="$app-promtail" +ynh_config_add_systemd --template="loki.service" +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-promtail" --description="Promtail daemon" --log="/var/log/$app/promtail.log" # Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append +ynh_config_add_logrotate #================================================= # 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_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" --action="start" --log_path="/var/log/$app/loki.log" --wait_until="Loki started" +ynh_systemctl --service="$app-promtail" --action="start" --log_path="/var/log/$app/promtail.log" --wait_until="server listening on addresses" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed" diff --git a/sources/extra_files/loki/.gitignore b/sources/extra_files/loki/.gitignore deleted file mode 100644 index 783a4ae..0000000 --- a/sources/extra_files/loki/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*~ -*.sw[op] diff --git a/sources/extra_files/loki/merge_yaml.sh b/sources/extra_files/loki/merge_yaml.sh deleted file mode 100644 index 1e55ffc..0000000 --- a/sources/extra_files/loki/merge_yaml.sh +++ /dev/null @@ -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'))))"