1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/wireguard_ynh.git synced 2024-09-03 20:35:58 +02:00

Enhance services

This commit is contained in:
tituspijean 2021-03-21 14:35:36 +01:00
parent 927ee7b3ed
commit 1f64caad7a
8 changed files with 42 additions and 53 deletions

View file

@ -1,3 +1,2 @@
Cmnd_Alias WIREGUARDSERVICE = /bin/systemctl restart wg-quick@wg0.service Cmnd_Alias WIREGUARDSERVICE = /usr/bin/systemctl restart wg-quick@wg0.service
%__USER__ ALL = NOPASSWD: WIREGUARDSERVICE
__USER__ ALL = NOPASSWD: WIREGUARDSERVICE

View file

@ -6,4 +6,4 @@ After=network.target
Type=oneshot Type=oneshot
User=__APP__ User=__APP__
Group=__APP__ Group=__APP__
ExecStart=/bin/systemctl restart wg-quick@wg0.service ExecStart=/usr/bin/systemctl restart wg-quick@wg0.service

View file

@ -60,9 +60,9 @@ ynh_backup --src_path="/etc/logrotate.d/$app"
# BACKUP SYSTEMD # BACKUP SYSTEMD
#================================================= #=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup --src_path=/etc/systemd/system/wireguard_ui.service ynh_backup --src_path=/etc/systemd/system/wireguard_ui.service
ynh_backup --src_path=/etc/systemd/system/wireguard.path ynh_backup --src_path=/etc/systemd/system/wireguard_ui_conf.path
ynh_backup --src_path=/etc/systemd/system/wireguard_ui_conf.service
ynh_backup --src_path="/etc/sudoers.d/${app}_ynh" ynh_backup --src_path="/etc/sudoers.d/${app}_ynh"
#================================================= #=================================================

View file

@ -135,7 +135,7 @@ ynh_replace_string --match_string="__PORT_WG__" --replace_string="$port_wg" --ta
# Create WireGuard configuration directory # Create WireGuard configuration directory
mkdir -p /etc/wireguard mkdir -p /etc/wireguard
# Add interace configuration file for WireGuard # Add interface configuration file for WireGuard
cp ../conf/wg0.conf /etc/wireguard/wg0.conf cp ../conf/wg0.conf /etc/wireguard/wg0.conf
ynh_replace_string --match_string="__PORT_WG__" --replace_string="$port_wg" --target_file="/etc/wireguard/wg0.conf" ynh_replace_string --match_string="__PORT_WG__" --replace_string="$port_wg" --target_file="/etc/wireguard/wg0.conf"
ynh_replace_string --match_string="__PRIVATE_KEY__" --replace_string="$(wg genkey)" --target_file="/etc/wireguard/wg0.conf" ynh_replace_string --match_string="__PRIVATE_KEY__" --replace_string="$(wg genkey)" --target_file="/etc/wireguard/wg0.conf"
@ -149,11 +149,11 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=1
ynh_add_systemd_config --service=wireguard_ui --template=wireguard_ui.service --others_var="port" ynh_add_systemd_config --service=wireguard_ui --template=wireguard_ui.service --others_var="port"
# Create a dedicated systemd config for monitoring WireGuard's configuration # Create a dedicated systemd config for monitoring WireGuard's configuration
cp ../conf/wireguard.path /etc/systemd/system/wireguard.path cp ../conf/wireguard_ui_conf.path /etc/systemd/system/wireguard_ui_conf.path
systemctl enable --quiet wireguard.path systemctl enable --quiet wireguard_ui_conf.path
# Create a dedicated systemd config for restarting WireGuard # Create a dedicated systemd config for restarting WireGuard when its configuration changes
ynh_add_systemd_config --service=wireguard --template=wireguard.service --others_var="port_wg" ynh_add_systemd_config --service=wireguard_ui_conf --template=wireguard_ui_conf.service --others_var="port_wg"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
@ -168,21 +168,13 @@ chmod -R 750 $final_path/db
chown -R $app:$app /etc/wireguard chown -R $app:$app /etc/wireguard
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add wireguard --description "WireGuard" --needs_exposed_ports $port_wg --test_status "wg show | grep wg0" yunohost service add wg-quick@wg0 --description "WireGuard" --needs_exposed_ports $port_wg
yunohost service add wireguard_ui --description "WireGuard UI" --log "/var/log/$app/ui.log" yunohost service add wireguard_ui --description "WireGuard UI"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE

View file

@ -27,26 +27,33 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# REMOVE SERVICE INTEGRATION IN YUNOHOST # REMOVE SERVICE INTEGRATION IN YUNOHOST
#================================================= #=================================================
# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) # Remove the services from the list of services known by Yunohost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status wireguard_ui >/dev/null if ynh_exec_warn_less yunohost service status wireguard_ui >/dev/null
then then
ynh_script_progression --message="Removing WireGuard UI service integration..." --weight=1 ynh_script_progression --message="Removing WireGuard UI service integration..." --weight=1
yunohost service remove wireguard_ui yunohost service remove wireguard_ui
fi fi
if ynh_exec_warn_less yunohost service status wg-quick@wg0 >/dev/null
then
ynh_script_progression --message="Removing WireGuard service integration..." --weight=1
yunohost service remove wg-quick@wg0
fi
#================================================= #=================================================
# STOP AND REMOVE SERVICE # STOP AND REMOVE SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
# YunoHost does not handle services not ending with .service, let's remove it manually # YunoHost does not handle services not ending with .service, let's remove it manually
systemctl stop wireguard.path systemctl stop wireguard_ui_conf.path
systemctl disable wireguard.path --quiet systemctl disable wireguard_ui_conf.path --quiet
ynh_secure_remove --file="/etc/systemd/system/wireguard.path" ynh_secure_remove --file="/etc/systemd/system/wireguard_ui_conf.path"
systemctl daemon-reload systemctl daemon-reload
# Remove the dedicated systemd configs # Remove the dedicated systemd configs
ynh_remove_systemd_config --service=wireguard ynh_remove_systemd_config --service=wireguard_ui_conf
ynh_remove_systemd_config --service=wireguard_ui ynh_remove_systemd_config --service=wireguard_ui
#================================================= #=================================================

View file

@ -111,17 +111,17 @@ ynh_remove_extra_repo --name=$app
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path=/etc/systemd/system/wireguard_ui.service ynh_restore_file --origin_path=/etc/systemd/system/wireguard_ui.service
ynh_restore_file --origin_path=/etc/systemd/system/wireguard.path ynh_restore_file --origin_path=/etc/systemd/system/wireguard_ui_conf.path
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore_file --origin_path=/etc/systemd/system/wireguard_ui_conf.service
systemctl enable --quiet wireguard.path systemctl enable --quiet wireguard_ui_conf.path
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add wireguard --description "WireGuard" --needs_exposed_ports $port_wg --test_status "wg show | grep wg0" yunohost service add wg-quick@wg0 --description "WireGuard" --needs_exposed_ports "$port_wg"
yunohost service add wireguard_ui --description "WireGuard UI" --log "/var/log/$app/ui.log" yunohost service add wireguard_ui --description "WireGuard UI" --log "/var/log/$app/ui.log"
#================================================= #=================================================
@ -137,12 +137,7 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=wireguard_ui --action="start" --line_match="http server started" --log_path="systemd" --timeout=30 ynh_systemd_action --service_name=wireguard_ui --action="start" --line_match="http server started" --log_path="systemd" --timeout=30
sleep 5 sleep 5
ynh_systemd_action --service_name=wg-quick@wg0 --action="start" --line_match="Started WireGuard via wg-quick(8) for wg0." --log_path="systemd" --timeout=30
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION

View file

@ -84,6 +84,13 @@ if [ -f "/etc/sudoers.d/${app}_ynh" ]; then
ynh_replace_string "__USER__" "${app}" /etc/sudoers.d/${app}_ynh ynh_replace_string "__USER__" "${app}" /etc/sudoers.d/${app}_ynh
fi fi
# Remove deprecated services
if systemctl list-units --full -all | grep -Fq "wireguard.path"; then
systemctl disable --now --quiet wireguard.path
ynh_secure_remove --file="/etc/systemd/system/wireguard.path"
fi
ynh_remove_systemd_config --service="wireguard.service"
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
@ -106,8 +113,7 @@ ynh_abort_if_errors
ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=wireguard_ui --action="stop" --line_match="Stopped WireGuard UI" --log_path="systemd" --timeout=30 ynh_systemd_action --service_name=wireguard_ui --action="stop" --line_match="Stopped WireGuard UI" --log_path="systemd" --timeout=30
systemctl disable --now --quiet wireguard.path ynh_systemd_action --service_name=wg-quick@wg0 --action="stop" --line_match="Stopped WireGuard via wg-quick(8) for wg0." --log_path="systemd" --timeout=30
ynh_systemd_action --service_name=wireguard --action="stop"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
@ -170,11 +176,8 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
ynh_add_systemd_config --service=wireguard_ui --template=wireguard_ui.service --others_var="port" ynh_add_systemd_config --service=wireguard_ui --template=wireguard_ui.service --others_var="port"
# Create a dedicated systemd config for monitoring WireGuard's configuration # Create a dedicated systemd config for monitoring WireGuard's configuration
cp ../conf/wireguard.path /etc/systemd/system/wireguard.path cp ../conf/wireguard_ui_conf.path /etc/systemd/system/wireguard_ui_conf.path
systemctl enable --quiet wireguard.path systemctl enable --quiet wireguard_ui_conf.path
# Create a dedicated systemd config for restarting WireGuard
ynh_add_systemd_config --service=wireguard --template=wireguard.service --others_var="port_wg"
#================================================= #=================================================
# CONFIGURING WIREGUARD # CONFIGURING WIREGUARD
@ -198,21 +201,13 @@ chown -R root: $final_path
chown -R $app: $final_path/db chown -R $app: $final_path/db
chmod -R 750 $final_path/db chmod -R 750 $final_path/db
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add wireguard --description "WireGuard" --needs_exposed_ports "$port_wg" --test_status "wg show | grep wg0" yunohost service add wg-quick@wg0 --description "WireGuard" --needs_exposed_ports "$port_wg"
yunohost service add wireguard_ui --description "WireGuard UI" --log "/var/log/$app/ui.log" yunohost service add wireguard_ui --description "WireGuard UI"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
@ -222,6 +217,7 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name=wireguard_ui --action="start" --line_match="http server started" --log_path="systemd" --timeout=30 ynh_systemd_action --service_name=wireguard_ui --action="start" --line_match="http server started" --log_path="systemd" --timeout=30
sleep 5 sleep 5
ynh_systemd_action --service_name=wg-quick@wg0 --action="start" --line_match="Started WireGuard via wg-quick(8) for wg0." --log_path="systemd" --timeout=30
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX