aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--\35
-rw-r--r--modules/scripts/warp-start.sh34
-rw-r--r--modules/scripts/warp-stop.sh32
3 files changed, 90 insertions, 11 deletions
diff --git a/\ b/\
new file mode 100644
index 0000000..a5f566d
--- /dev/null
+++ b/\
@@ -0,0 +1,35 @@
+set -euo pipefail
+
+stop_daemon() {
+ echo "Killing warp-svc process..."
+ sudo pkill -x warp-svc
+ echo "warp-svc is not running."
+}
+
+disconnect_client() {
+ echo "Disconnecting from WARP..."
+ if warp-cli status 2>&1 | grep -qi "Connected"; then
+ sudo warp-cli disconnect
+ echo "Disconnected."
+ else
+ echo "WARP is already disconnected."
+ fi
+}
+
+main() {
+ if [[ -t 2 ]]; then
+ echo -e "\e[31mERROR:\e[0m Must be run as root" >&2
+ else
+ echo "ERROR: Must be run as root" >&2
+ fi
+
+ disconnect_client
+ stop_daemon
+
+ echo "Final status:"
+ warp-cli status || true
+ sudo systemd-resolve --flush-caches
+ sudo systemctl restart systemd-resolved
+}
+
+main "$@"
diff --git a/modules/scripts/warp-start.sh b/modules/scripts/warp-start.sh
index 28b9457..49f807d 100644
--- a/modules/scripts/warp-start.sh
+++ b/modules/scripts/warp-start.sh
@@ -1,18 +1,31 @@
set -euo pipefail
-# Optional: where to log the daemon
LOGFILE="/var/log/warp-svc.log"
+DAEMON_TIMEOUT=30 # seconds
start_daemon() {
if ! pgrep -x warp-svc >/dev/null 2>&1; then
echo "Starting warp-svc daemon..."
sudo nohup warp-svc >>"$LOGFILE" 2>&1 &
- sleep 2
else
echo "warp-svc already running."
fi
}
+wait_for_daemon() {
+ echo "Waiting for warp-svc to become ready..."
+ for ((i=1; i<=DAEMON_TIMEOUT; i++)); do
+ if warp-cli status >/dev/null 2>&1; then
+ echo "warp-svc is ready."
+ return 0
+ fi
+ sleep 1
+ done
+
+ echo "ERROR: warp-svc did not become ready within ${DAEMON_TIMEOUT}s" >&2
+ exit 1
+}
+
is_registered() {
if warp-cli status 2>&1 | grep -qi "Registration missing"; then
return 1
@@ -22,16 +35,26 @@ is_registered() {
register_client() {
echo "Registering client..."
- warp-cli registration new
+ sudo warp-cli registration new
}
connect_client() {
echo "Connecting to WARP..."
- warp-cli connect
+ sudo warp-cli connect
}
main() {
+ [[ "${EUID:-$(id -u)}" -eq 0 ]] || {
+ if [[ -t 2 ]]; then
+ echo -e "\e[31mERROR:\e[0m Must be run as root" >&2
+ else
+ echo "ERROR: Must be run as root" >&2
+ fi
+ exit 1
+ }
+
start_daemon
+ wait_for_daemon
if ! is_registered; then
register_client
@@ -45,4 +68,5 @@ main() {
warp-cli status
}
-main "$@"
+main
+
diff --git a/modules/scripts/warp-stop.sh b/modules/scripts/warp-stop.sh
index c374c8a..13b0c96 100644
--- a/modules/scripts/warp-stop.sh
+++ b/modules/scripts/warp-stop.sh
@@ -1,18 +1,26 @@
set -euo pipefail
stop_daemon() {
- if systemctl list-unit-files | grep -q '^warp-svc\.service'; then
- echo "Stopping warp-svc via systemd..."
- sudo systemctl stop warp-svc.service
- return
- fi
+ echo "Stopping warp-svc process..."
if pgrep -x warp-svc >/dev/null 2>&1; then
- echo "Killing warp-svc process..."
sudo pkill -x warp-svc
else
echo "warp-svc is not running."
+ return 0
fi
+
+ echo "Waiting for warp-svc to stop..."
+ for _ in {1..30}; do
+ if ! pgrep -x warp-svc >/dev/null 2>&1; then
+ echo "warp-svc stopped."
+ return 0
+ fi
+ sleep 1
+ done
+
+ echo "ERROR: warp-svc did not stop in time" >&2
+ exit 1
}
disconnect_client() {
@@ -26,13 +34,25 @@ disconnect_client() {
}
main() {
+ [[ "${EUID:-$(id -u)}" -eq 0 ]] || {
+ if [[ -t 2 ]]; then
+ echo -e "\e[31mERROR:\e[0m Must be run as root" >&2
+ else
+ echo "ERROR: Must be run as root" >&2
+ fi
+ exit 1
+ }
+
disconnect_client
stop_daemon
echo "Final status:"
warp-cli status || true
+
+ echo "Flushing DNS and restarting systemd-resolved..."
sudo systemd-resolve --flush-caches
sudo systemctl restart systemd-resolved
}
main "$@"
+