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/remove

146 lines
4.6 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-23 05:05:47 +02:00
source ynh_install_go
2022-07-20 12:04:29 +02:00
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2022-07-20 12:07:54 +02:00
ynh_script_progression --message="Loading installation settings..."
2022-07-20 12:04:29 +02:00
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
2022-07-21 08:24:29 +02:00
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
2022-07-20 12:04:29 +02:00
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
2022-07-21 08:24:29 +02:00
node_type=$(ynh_app_setting_get --app=$app --key=node_type)
2022-07-23 04:57:16 +02:00
driver_lxc=$(ynh_app_setting_get --app=$app --key=driver_lxc)
2022-07-21 08:24:29 +02:00
rpc_port=$(ynh_app_setting_get --app=$app --key=rpc_port)
serf_port=$(ynh_app_setting_get --app=$app --key=serf_port)
2022-07-20 12:04:29 +02:00
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
# 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
2022-07-20 12:07:54 +02:00
ynh_script_progression --message="Removing $app service integration..."
2022-07-20 12:04:29 +02:00
yunohost service remove $app
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
2022-07-20 12:07:54 +02:00
ynh_script_progression --message="Stopping and removing the systemd service..."
2022-07-20 12:04:29 +02:00
2022-07-22 03:48:31 +02:00
ynh_exec_warn_less nomad node drain -self -enable
2022-07-20 12:04:29 +02:00
# Remove the dedicated systemd config
ynh_remove_systemd_config
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
2022-07-20 12:07:54 +02:00
ynh_script_progression --message="Removing logrotate configuration..."
2022-07-20 12:04:29 +02:00
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
2022-07-20 12:07:54 +02:00
ynh_script_progression --message="Removing NGINX web server configuration..."
2022-07-20 12:04:29 +02:00
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# CLOSE A PORT
#=================================================
2022-07-21 08:24:29 +02:00
if yunohost firewall list | grep -q "\- $rpc_port$"
2022-07-20 12:04:29 +02:00
then
2022-07-21 08:24:29 +02:00
ynh_script_progression --message="Closing port $rpc_port..."
ynh_exec_warn_less yunohost firewall disallow TCP $rpc_port
2022-07-20 12:04:29 +02:00
fi
2022-07-21 08:24:29 +02:00
if yunohost firewall list | grep -q "\- $serf_port$"
then
ynh_script_progression --message="Closing port $serf_port..."
ynh_exec_warn_less yunohost firewall disallow TCP $serf_port
fi
2022-07-20 12:04:29 +02:00
2022-07-21 08:24:29 +02:00
if [ "$node_type" == "client" ]
then
2022-07-23 04:57:16 +02:00
if [ $driver_lxc -eq 1 ]
then
lxc_bridge=$(ynh_app_setting_get --app=$app --key=lxc_bridge)
ynh_systemd_action --service_name=lxc-net --action="stop"
systemctl disable lxc-net --quiet
ynh_secure_remove --file="/etc/default/lxc-net"
ynh_secure_remove --file="/etc/lxc/default.conf"
ynh_secure_remove --file="/etc/dnsmasq.d/lxd"
systemctl restart dnsmasq
fi
2022-07-21 08:24:29 +02:00
fi
2022-07-20 12:04:29 +02:00
2022-07-22 02:31:36 +02:00
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..."
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
2022-07-22 14:32:37 +02:00
ynh_remove_go
2022-07-22 02:31:36 +02:00
2022-07-22 03:42:13 +02:00
#=================================================
# REMOVE DATA DIR
#=================================================
# Remove the data directory if --purge option is used
if [ "${YNH_APP_PURGE:-0}" -eq 1 ]
then
ynh_script_progression --message="Removing app data directory..."
ynh_secure_remove --file="$datadir"
fi
2022-07-20 12:04:29 +02:00
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE VARIOUS FILES
#=================================================
2022-07-20 12:07:54 +02:00
ynh_script_progression --message="Removing various files..."
2022-07-20 12:04:29 +02:00
# Remove a directory securely
2022-07-21 08:24:29 +02:00
ynh_secure_remove --file="$config_path"
2022-07-20 12:04:29 +02:00
# Remove the log files
ynh_secure_remove --file="/var/log/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
2022-07-20 12:07:54 +02:00
ynh_script_progression --message="Removing the dedicated system user..."
2022-07-20 12:04:29 +02:00
# Delete a system user
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================
2022-07-20 12:07:54 +02:00
ynh_script_progression --message="Removal of $app completed"