From 1c1b787d54763281beb1684c80e9f82b7d551b50 Mon Sep 17 00:00:00 2001 From: Pavel Muhortov Date: Thu, 17 Aug 2023 13:33:21 +0300 Subject: [PATCH] added status --- wg-heavy@wg1.service | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/wg-heavy@wg1.service b/wg-heavy@wg1.service index 6e20d2c..6dc113f 100644 --- a/wg-heavy@wg1.service +++ b/wg-heavy@wg1.service @@ -1,13 +1,13 @@ #! /bin/sh -# chkconfig: 2345 20 80 +# chkconfig: 2345 20 80 ### BEGIN INIT INFO -# Provides: wireguard -# Required-Start: $all -# Required-Stop: -# Default-Start: 2 3 4 5 -# Default-Stop: -# Short-Description: Launch Wireguard without creating route table +# Provides: wireguard +# Required-Start: $all +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: +# Short-Description: Launch Wireguard without creating route table ### END INIT INFO wifname=$(basename -s .service "$0" | cut -d'@' -f2) @@ -41,7 +41,15 @@ stop() { rm -f "/etc/wireguard/${wifname}.key" } -case "$1" in +status() { + if ip a grep -q -w "${wifname}"; then + ip a | grep -w "${wifname}" + else + echo "${wifname} down" + fi +} + +case "$1" in start) start ;; @@ -50,10 +58,14 @@ case "$1" in ;; restart) stop + sleep 1 start ;; + status) + status + ;; *) - echo "Usage: $0 {start|stop|restart}" + echo "Usage: $0 {start|stop|restart|status}" esac -exit 0 \ No newline at end of file +exit 0