#!/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_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 # 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" # 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" 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 #================================================= ynh_script_progression --message="Updating a configuration file..." --weight=1 ynh_add_config --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" ynh_add_config --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" #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= 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" 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 #================================================= # 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" --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" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed" --last