From 6029b901d5db6824851b15194b02327edcc85419 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 26 Oct 2015 00:08:15 -0400 Subject: initial commit --- Makefile | 17 +++++++++++++++++ netctl-hook | 3 +++ network-online | 30 ++++++++++++++++++++++++++++++ network-online@.service | 7 +++++++ 4 files changed, 57 insertions(+) create mode 100644 Makefile create mode 100755 netctl-hook create mode 100755 network-online create mode 100644 network-online@.service 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 -- cgit v1.2.3-54-g00ecf