mirror of
https://github.com/YunoHost-Apps/wireguard_ynh.git
synced 2024-09-03 20:35:58 +02:00
Simplify services
This commit is contained in:
parent
7bdf34ac71
commit
b147c0c7cb
9 changed files with 57 additions and 71 deletions
8
conf/wireguard@.path
Normal file
8
conf/wireguard@.path
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Watch WireGuard %I.conf for changes
|
||||||
|
|
||||||
|
[Path]
|
||||||
|
PathModified=/etc/wireguard/%I.conf
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
13
conf/wireguard@.service
Normal file
13
conf/wireguard@.service
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
[Unit]
|
||||||
|
Description=WireGuard on %I
|
||||||
|
After=network-online.target nss-lookup.target
|
||||||
|
Wants=network-online.target nss-lookup.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
RemainAfterExit=yes
|
||||||
|
ExecStart=/bin/systemctl restart wg-quick@%I.service
|
||||||
|
ExecStop=/bin/systemctl stop wg-quick@%I.service
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -1,8 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=Watch WireGuard wg0.conf for changes
|
|
||||||
|
|
||||||
[Path]
|
|
||||||
PathModified=/etc/wireguard/wg0.conf
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
|
@ -1,8 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=WireGuard restart
|
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=oneshot
|
|
||||||
User=root
|
|
||||||
ExecStart=systemctl restart wg-quick@wg0.service
|
|
|
@ -55,8 +55,8 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
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_ui_conf.path
|
ynh_backup --src_path=/etc/systemd/system/wireguard@.path
|
||||||
ynh_backup --src_path=/etc/systemd/system/wireguard_ui_conf.service
|
ynh_backup --src_path=/etc/systemd/system/wireguard@.service
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP VARIOUS FILES
|
# BACKUP VARIOUS FILES
|
||||||
|
|
|
@ -147,12 +147,12 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
||||||
ynh_add_systemd_config --service=wireguard_ui --template=wireguard_ui.service
|
ynh_add_systemd_config --service=wireguard_ui --template=wireguard_ui.service
|
||||||
|
|
||||||
# Create a dedicated systemd config for monitoring WireGuard's configuration
|
# Create a dedicated systemd config for monitoring WireGuard's configuration
|
||||||
cp ../conf/wireguard_ui_conf.path /etc/systemd/system/wireguard_ui_conf.path
|
cp ../conf/wireguard@.path /etc/systemd/system/wireguard@.path
|
||||||
systemctl enable --quiet wireguard_ui_conf.path
|
systemctl enable --quiet wireguard@wg0.path
|
||||||
|
|
||||||
# Create a dedicated systemd config for restarting WireGuard when its configuration changes
|
# Create a dedicated systemd config for WireGuard
|
||||||
ynh_add_systemd_config --service=wireguard_ui_conf --template=wireguard_ui_conf.service
|
cp ../conf/wireguard@.service /etc/systemd/system/wireguard@.service
|
||||||
systemctl enable --quiet wireguard_ui_conf.service
|
systemctl enable --quiet wireguard@wg0.service
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
|
@ -174,7 +174,7 @@ chown -R $app: /etc/wireguard
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
||||||
|
|
||||||
yunohost service add wg-quick@wg0 --description="WireGuard VPN" --needs_exposed_ports="$port_wg" --test_status="wg show | grep wg0"
|
yunohost service add wireguard@wg0 --description="WireGuard VPN" --needs_exposed_ports="$port_wg" --test_status="wg show | grep wg0"
|
||||||
yunohost service add wireguard_ui --description="WireGuard UI"
|
yunohost service add wireguard_ui --description="WireGuard UI"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -185,14 +185,6 @@ ynh_script_progression --message="Starting the systemd service for the UI..." --
|
||||||
# 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
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# START VPN SYSTEMD SERVICE
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Starting the systemd service for the VPN..." --weight=1
|
|
||||||
|
|
||||||
# Start and enable a systemd service
|
|
||||||
systemctl enable --now --quiet wg-quick@wg0
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SSOWAT
|
# SETUP SSOWAT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -35,10 +35,10 @@ then
|
||||||
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
|
if ynh_exec_warn_less yunohost service status wireguard@wg0 >/dev/null
|
||||||
then
|
then
|
||||||
ynh_script_progression --message="Removing WireGuard service integration..." --weight=1
|
ynh_script_progression --message="Removing WireGuard service integration..." --weight=1
|
||||||
yunohost service remove wg-quick@wg0
|
yunohost service remove wireguard@wg0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -47,13 +47,14 @@ fi
|
||||||
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_ui_conf.path
|
systemctl stop wireguard@wg0.path
|
||||||
systemctl disable wireguard_ui_conf.path --quiet
|
systemctl disable wireguard@wg0.path --quiet
|
||||||
ynh_secure_remove --file="/etc/systemd/system/wireguard_ui_conf.path"
|
ynh_secure_remove --file="/etc/systemd/system/wireguard@.path"
|
||||||
systemctl daemon-reload
|
|
||||||
|
systemctl stop wireguard@wg0.service
|
||||||
|
systemctl disable wireguard@wg0.service --quiet
|
||||||
|
ynh_secure_remove --file="/etc/systemd/system/wireguard@.service"
|
||||||
|
|
||||||
# Remove the dedicated systemd configs
|
|
||||||
ynh_remove_systemd_config --service=wireguard_ui_conf
|
|
||||||
ynh_remove_systemd_config --service=wireguard_ui
|
ynh_remove_systemd_config --service=wireguard_ui
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -110,19 +110,19 @@ 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_ui_conf.path
|
ynh_restore_file --origin_path=/etc/systemd/system/wireguard@.path
|
||||||
ynh_restore_file --origin_path=/etc/systemd/system/wireguard_ui_conf.service
|
ynh_restore_file --origin_path=/etc/systemd/system/wireguard@.service
|
||||||
|
|
||||||
systemctl enable --quiet wireguard_ui.service
|
systemctl enable --quiet wireguard_ui.service
|
||||||
systemctl enable --quiet wireguard_ui_conf.path
|
systemctl enable --quiet wireguard@wg0.path
|
||||||
systemctl enable --quiet wireguard_ui_conf.service
|
systemctl enable --quiet wireguard@wg0.service
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# 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 wg-quick@wg0 --description="WireGuard VPN" --needs_exposed_ports="$port_wg" --test_status="wg show | grep wg0"
|
yunohost service add wireguard@wg0 --description="WireGuard VPN" --needs_exposed_ports="$port_wg" --test_status="wg show | grep wg0"
|
||||||
yunohost service add wireguard_ui --description="WireGuard UI"
|
yunohost service add wireguard_ui --description="WireGuard UI"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -138,14 +138,6 @@ ynh_script_progression --message="Starting the systemd service for the UI..." --
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# START VPN SYSTEMD SERVICE
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Starting the systemd service for the VPN..." --weight=1
|
|
||||||
|
|
||||||
# Start and enable a systemd service
|
|
||||||
systemctl enable --now --quiet wg-quick@wg0
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -98,11 +98,15 @@ if [ -f "/etc/sudoers.d/${app}_ynh" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove deprecated services
|
# Remove deprecated services
|
||||||
if systemctl list-units --full -all | grep -Fq "wireguard.path"; then
|
if systemctl list-units --full -all | grep -Fq "wireguard_ui_conf.path"; then
|
||||||
systemctl disable --now --quiet wireguard.path
|
systemctl disable --now --quiet wireguard_ui_conf.path
|
||||||
ynh_secure_remove --file="/etc/systemd/system/wireguard.path"
|
ynh_secure_remove --file="/etc/systemd/system/wireguard_ui_conf.path"
|
||||||
|
fi
|
||||||
|
if systemctl list-units --full -all | grep -Fq "wireguard_ui_conf.service"; then
|
||||||
|
systemctl disable --now --quiet wireguard_ui_conf.service
|
||||||
|
ynh_secure_remove --file="/etc/systemd/system/wireguard_ui_conf.service"
|
||||||
|
yunohost service remove wireguard_ui_conf
|
||||||
fi
|
fi
|
||||||
ynh_remove_systemd_config --service="wireguard.service"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD UPGRADE STEPS
|
# STANDARD UPGRADE STEPS
|
||||||
|
@ -112,7 +116,7 @@ ynh_remove_systemd_config --service="wireguard.service"
|
||||||
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
|
||||||
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@wg0 --action="stop"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
|
@ -175,12 +179,12 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
||||||
ynh_add_systemd_config --service=wireguard_ui --template=wireguard_ui.service
|
ynh_add_systemd_config --service=wireguard_ui --template=wireguard_ui.service
|
||||||
|
|
||||||
# Create a dedicated systemd config for monitoring WireGuard's configuration
|
# Create a dedicated systemd config for monitoring WireGuard's configuration
|
||||||
cp ../conf/wireguard_ui_conf.path /etc/systemd/system/wireguard_ui_conf.path
|
cp ../conf/wireguard@.path /etc/systemd/system/wireguard@.path
|
||||||
systemctl enable --quiet wireguard_ui_conf.path
|
systemctl enable --quiet wireguard@wg0.path
|
||||||
|
|
||||||
# Create a dedicated systemd config for restarting WireGuard when its configuration changes
|
# Create a dedicated systemd config for restarting WireGuard when its configuration changes
|
||||||
ynh_add_systemd_config --service=wireguard_ui_conf --template=wireguard_ui_conf.service
|
cp ../conf/wireguard@.service /etc/systemd/system/wireguard@.service
|
||||||
systemctl enable --quiet wireguard_ui_conf.service
|
systemctl enable --quiet wireguard@wg0.service
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CONFIGURING WIREGUARD
|
# CONFIGURING WIREGUARD
|
||||||
|
@ -213,7 +217,7 @@ chown -R $app: /etc/wireguard
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
||||||
|
|
||||||
yunohost service add wg-quick@wg0 --description="WireGuard VPN" --needs_exposed_ports="$port_wg" --test_status="wg show | grep wg0"
|
yunohost service add wireguard@wg0 --description="WireGuard VPN" --needs_exposed_ports="$port_wg" --test_status="wg show | grep wg0"
|
||||||
yunohost service add wireguard_ui --description="WireGuard UI"
|
yunohost service add wireguard_ui --description="WireGuard UI"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -224,14 +228,6 @@ ynh_script_progression --message="Starting the systemd service for the UI..." --
|
||||||
# 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
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# START VPN SYSTEMD SERVICE
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Starting the systemd service for the VPN..." --weight=1
|
|
||||||
|
|
||||||
# Start and enable a systemd service
|
|
||||||
systemctl enable --now --quiet wg-quick@wg0
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RELOAD NGINX
|
# RELOAD NGINX
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Reference in a new issue