1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/nomad_ynh.git synced 2024-09-03 19:55:53 +02:00
nomad_ynh/scripts/install

119 lines
4.3 KiB
Text
Raw Normal View History

2022-07-20 12:04:29 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
2022-07-21 08:24:29 +02:00
source ynh_install_go
2022-07-20 12:04:29 +02:00
source /usr/share/yunohost/helpers
#=================================================
2024-02-14 14:13:22 +01:00
# INITIALIZE AND STORE SETTINGS
2022-07-20 12:04:29 +02:00
#=================================================
2022-07-23 16:56:59 +02:00
client_lxc_bridge="lxcbr0"
client_lxc_plage_ip="10.1.44"
client_lxc_main_iface=$(ip route | grep default | awk '{print $5;}')
2024-02-14 14:13:22 +01:00
ynh_app_setting_set --app="$app" --key=client_lxc_bridge --value="$client_lxc_bridge"
ynh_app_setting_set --app="$app" --key=client_lxc_plage_ip --value="$client_lxc_plage_ip"
ynh_app_setting_set --app="$app" --key=client_lxc_main_iface --value="$client_lxc_main_iface"
2022-07-21 08:24:29 +02:00
2022-07-20 12:04:29 +02:00
#=================================================
# CREATE DATA DIRECTORY
#=================================================
2024-02-14 14:13:22 +01:00
ynh_script_progression --message="Configuring the data directory..." --weight=1
2022-07-20 12:04:29 +02:00
2024-02-14 14:13:22 +01:00
chmod -R o-rwx "$data_dir"
chown -R "$app:$app" "$data_dir"
2022-07-21 08:24:29 +02:00
#=================================================
2022-07-23 04:57:16 +02:00
# BUILD DRIVERS
2022-07-21 08:24:29 +02:00
#=================================================
2024-02-14 14:13:22 +01:00
if [ "$node_type" == "client" ] && [ "$driver_lxc" -eq 1 ]; then
ynh_script_progression --message="Building LXC driver..."
2022-07-21 08:24:29 +02:00
2024-02-14 14:13:22 +01:00
ynh_exec_warn_less ynh_install_go --go_version="$go_version"
2022-07-21 08:24:29 +02:00
2024-02-14 14:13:22 +01:00
ynh_setup_source --dest_dir="$install_dir/driver_lxc" --source_id="driver_lxc"
pushd "$install_dir/driver_lxc"
ynh_use_go
export GOPATH="$install_dir/driver_lxc/go"
export GOCACHE="$install_dir/driver_lxc/.cache"
ynh_exec_warn_less "$ynh_go" build
popd
mv -f "$install_dir/driver_lxc/nomad-driver-lxc" "$data_dir/plugins/nomad-driver-lxc"
ynh_secure_remove --file="$install_dir/driver_lxc"
2022-07-21 08:24:29 +02:00
fi
2022-07-20 12:04:29 +02:00
#=================================================
# ADD A CONFIGURATION
#=================================================
2022-09-03 18:58:58 +02:00
ynh_script_progression --message="Adding a configuration file..." --weight=1
2022-07-20 12:04:29 +02:00
2022-07-21 08:24:29 +02:00
config_path=/etc/$app.d
2024-02-14 14:13:22 +01:00
ynh_app_setting_set --app="$app" --key=config_path --value="$config_path"
2022-07-21 08:24:29 +02:00
2024-02-14 14:13:22 +01:00
mkdir -p "$config_path"
2022-07-20 12:04:29 +02:00
2024-02-14 14:13:22 +01:00
ynh_add_config --template="nomad.hcl" --destination="$config_path/nomad.hcl"
2022-07-21 08:24:29 +02:00
2024-02-14 14:13:22 +01:00
if [ "$node_type" == "server" ]; then
ynh_add_config --template="server.hcl" --destination="$config_path/server.hcl"
2022-07-21 08:24:29 +02:00
fi
2024-02-14 14:13:22 +01:00
if [ "$node_type" == "client" ]; then
ynh_add_config --template="client.hcl" --destination="$config_path/client.hcl"
if [ "$driver_lxc" -eq 1 ]; then
ynh_add_config --template="driver-lxc.hcl" --destination="$config_path/driver-lxc.hcl"
ynh_add_config --template="dnsmasq-lxd" --destination="/etc/dnsmasq.d/lxd"
systemctl restart dnsmasq
if [ ! "${PACKAGE_CHECK_EXEC:-0}" -eq 1 ]; then
ynh_add_config --template="lxc-net" --destination="/etc/default/lxc-net"
fi
ynh_add_config --template="default.conf" --destination="/etc/lxc/default.conf"
systemctl enable lxc-net --quiet
ynh_systemd_action --service_name=lxc-net --action="restart" --line_match="Finished LXC network bridge setup" --log_path="systemd"
fi
2022-07-21 08:24:29 +02:00
fi
2022-07-20 12:04:29 +02:00
2024-02-14 14:13:22 +01:00
chmod -R go-rwx,u-w "$config_path"
chown -R "$app:$app" "$config_path"
2022-07-20 12:04:29 +02:00
#=================================================
2024-02-14 14:13:22 +01:00
# SYSTEM CONFIGURATION
2022-07-20 12:04:29 +02:00
#=================================================
2024-02-14 14:13:22 +01:00
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
2022-07-20 12:04:29 +02:00
# Create a dedicated systemd config
2024-02-14 14:13:22 +01:00
case "$node_type" in
client) systemd_user="root" ;;
server) systemd_user="$app" ;;
esac
2022-07-20 12:04:29 +02:00
ynh_add_systemd_config
2024-02-14 14:13:22 +01:00
yunohost service add "$app" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port_rpc $port_serf"
2022-07-20 12:04:29 +02:00
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# START SYSTEMD SERVICE
#=================================================
2022-09-03 18:58:58 +02:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2022-07-20 12:04:29 +02:00
# Start a systemd service
2024-02-14 14:13:22 +01:00
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" --line_match="Nomad agent started"
2022-07-20 12:04:29 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2022-09-03 18:58:58 +02:00
ynh_script_progression --message="Installation of $app completed" --last