diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-10-26 00:08:15 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-10-26 00:08:15 -0400 |
commit | 6029b901d5db6824851b15194b02327edcc85419 (patch) | |
tree | 78039cbfc68eed8384d3ac19c0140f0554428c30 |
initial commit
-rw-r--r-- | Makefile | 17 | ||||
-rwxr-xr-x | netctl-hook | 3 | ||||
-rwxr-xr-x | network-online | 30 | ||||
-rw-r--r-- | network-online@.service | 7 |
4 files changed, 57 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2202bb7 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +install-targets = \ + $(DESTDIR)/etc/netctl/hooks/network-online \ + $(DESTDIR)/lib/systemd/system/network-online@.service \ + $(DESTDIR)/lib/network/network-online + +install: $(install-targets) +uninstall: + rm -f -- $(install-targets) +.PHONY: install uninstall + +$(DESTDIR)/etc/netctl/hooks/network-online: netctl-hook + install -Dm755 $< $@ +$(DESTDIR)/lib/systemd/system/network-online@.service: network-online@.service + install -Dm644 $< $@ +$(DESTDIR)/lib/network/network-online: network-online + install -Dm755 $< $@ + diff --git a/netctl-hook b/netctl-hook new file mode 100755 index 0000000..5190f02 --- /dev/null +++ b/netctl-hook @@ -0,0 +1,3 @@ +#!/hint/sh +printf -v ExecUpPost "systemctl start network-online@%q.service" "$(systemd-escape -- "$Profile")" +printf -v ExecDownPre "systemctl stop network-online@%q.service" "$(systemd-escape -- "$Profile")" 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 diff --git a/network-online@.service b/network-online@.service new file mode 100644 index 0000000..90195f9 --- /dev/null +++ b/network-online@.service @@ -0,0 +1,7 @@ +[Unit] +Description=Network %I is online + +[Service] +Type=simple +ExecStart=/lib/network/network-online start %I +ExecStop=/lib/network/network-online stop %I |