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

79 lines
3.1 KiB
Bash
Executable file

#!/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_setup_source --dest_dir="$install_dir" --source_id="loki"
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"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding 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"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
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 application logfile(s)
ynh_use_logrotate
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
# 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"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last