diff options
author | Rabi Shanker Guha <guha.rabishankar@gmail.com> | 2015-01-09 20:36:25 +0530 |
---|---|---|
committer | Rabi Shanker Guha <guha.rabishankar@gmail.com> | 2015-01-09 20:36:25 +0530 |
commit | 55f4303617ecd81f8729e8f45a64d14a4a0df41b (patch) | |
tree | 5489d9aed37018b4d664eb3ba6618a920d29d227 /sh | |
parent | Compatibility layer for multiple init systems (diff) | |
download | netifrc-55f4303617ecd81f8729e8f45a64d14a4a0df41b.tar.gz netifrc-55f4303617ecd81f8729e8f45a64d14a4a0df41b.tar.bz2 netifrc-55f4303617ecd81f8729e8f45a64d14a4a0df41b.zip |
Systemd Wrapper: to be called from unit file
Diffstat (limited to 'sh')
-rw-r--r-- | sh/systemd-wrapper.sh.in | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/sh/systemd-wrapper.sh.in b/sh/systemd-wrapper.sh.in new file mode 100644 index 0000000..d931200 --- /dev/null +++ b/sh/systemd-wrapper.sh.in @@ -0,0 +1,91 @@ +#!/bin/sh + +CONFDIR="@CONFDIR@" +LIBEXECDIR="@LIBEXECDIR@/sh" +INITDIR="@INITDIR@" +INIT=systemd + +usage() { + echo "netifrc systemd wrapper" + echo "Usage:" + echo " systemd-wrapper.sh -i <interface> <command>" + echo " where command is start|stop" +} + +die() { + echo "$@" + exit -1 +} + +while getopts "i:" opt; do + case $opt in + i) + RC_IFACE=$OPTARG;; + esac +done +shift $((OPTIND -1)) + +[ -z "$RC_IFACE" ] && die "Missing Parameter Interface" + +RC_SVCPREFIX="net" +RC_SVCNAME="$RC_SVCPREFIX"."$RC_IFACE" +RC_UNAME=$(uname) +# XXX Find out the systemd way of doing this +RC_GOINGDOWN=no + +# In Openrc systems this has value /run/openrc +SVCDIR="/run/netifrc" +# OpenRC saves values in $SVCDIR/options/$SVCNAME/$OPTION +# In non OpenRC setting this is saved in /run/netifrc/options/$SVCNAME/$OPTION +OPTIONSDIR="${SVCDIR}/options/${RC_SVCNAME}" +STATEDIR="${SVCDIR}/${RC_SVCNAME}" + +# Source the config file +if [ -f "$CONFDIR/$RC_SVCPREFIX" ]; then + . "$CONFDIR/$RC_SVCPREFIX" +fi + +# Source the actual runscript +if [ -f "$INITDIR/${RC_SVCPREFIX}.lo" ]; then + . "$INITDIR/${RC_SVCPREFIX}.lo" +else + echo "$INITDIR/${RC_SVCPREFIX}.lo : Init file missing or invalid path" + exit -1 +fi + +netifrc_init() { + # Ensure OPTIONSDIR is present and writeable + mkdir -p "$OPTIONSDIR" + if [ ! -w "$OPTIONSDIR" ]; then + eerror "${OPTIONSDIR} does not exist or is not writeable" + exit -1; + fi + # Ensure STATEDIR is present and writeable + mkdir -p "$STATEDIR" + if [ ! -w "$STATEDIR" ]; then + eerror "${STATEDIR} does not exist or is not writeable" + exit -1; + fi +} + +netifrc_cleanup() { + # Delete all the saved values + rm -f ${OPTIONSDIR}/* +} + +rc=0 +case $1 in + start) + netifrc_init + start + rc=$?;; + stop) + stop + netifrc_cleanup + rc=$?;; + *) + die "Unrecognised command $1";; +esac +exit $rc + +# vi: ts=4 sw=4 noexpandtab |