summaryrefslogtreecommitdiff
path: root/network-online
diff options
context:
space:
mode:
Diffstat (limited to 'network-online')
-rwxr-xr-xnetwork-online30
1 files changed, 30 insertions, 0 deletions
diff --git a/network-online b/network-online
new file mode 100755
index 0000000..a2fa8b0
--- /dev/null
+++ b/network-online
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+mode="$1"
+lock=/run/network-online/lock
+fifo=/run/network-online/"$2"
+PS4="$mode: "
+case "$mode" in
+ start)
+ trap 'rm -f -- "$fifo"' EXIT
+ set -x
+ mkdir -p /run/network-online || exit $?
+ exec 8>"$lock" || exit $?
+ flock -s 8 || exit $?
+ systemctl start network-online.target || exit $?
+
+ mkfifo "$fifo" || exit $?
+ cat "$fifo"
+ exec 8>&-
+ echo stopped >> "$fifo"
+ ;;
+ stop)
+ set -x
+ exec 8>"$lock" || exit $?
+ echo stopping >> "$fifo" || exit $?
+ cat "$fifo" || exit $?
+ if flock -x -n 8; then
+ systemctl stop network-online.target
+ rm -rf /run/network-online
+ fi
+ ;;
+esac