commit 282394359a9fdf4c0d780faf1184e3fe0f3bfee0
parent a1f344000bc37ded662288eb30904ec9e0dc7c93
Author: sin <sin@2f30.org>
Date: Thu, 13 Feb 2014 12:31:53 +0000
Import 20h's svc.
This was taken from: http://git.r-36.net/svc/
Thanks!
Diffstat:
6 files changed, 176 insertions(+), 14 deletions(-)
diff --git a/bin/rc.shutdown b/bin/rc.shutdown
@@ -17,10 +17,7 @@ echo Shutting down
hwclock -u -w
-echo $SVC | sed 's/ /\n/g' | tac | while read s; do
- echo Stopping $s
- /bin/rc.d/$s -k
-done
+svc -k
killall5 -15
sleep 5
diff --git a/bin/rc.svc b/bin/rc.svc
@@ -2,16 +2,8 @@
. /etc/rc.conf
-if [ -x /etc/dropbearkeys ]; then
- echo Generating dropbear keys
- /etc/dropbearkeys
-fi
-chmod 644 /etc/dropbearkeys
-
-for s in $SVC; do
- echo Starting $s
- /bin/rc.d/$s -s
-done
+svc -c
+svc -s
echo Running rc.local
[ -x /bin/rc.local ] && /bin/rc.local
diff --git a/bin/svc b/bin/svc
@@ -0,0 +1,114 @@
+#!/bin/sh
+#
+# See LICENSE file for license details.
+#
+
+BASEDIR="/bin/svc.d"
+BASENAME="$(basename $0)"
+
+[ -d "$BASEDIR" ] || mkdir -p "$BASEDIR"
+cd $BASEDIR
+
+usage() {
+ printf "usage: %s [-acdklrs] [service]\n" "$BASENAME" >&2
+ exit 1
+}
+
+if [ $# -lt 1 ];
+then
+ usage
+fi
+
+runservice() {
+ service="$1"
+ dir="$2"
+ cmd="$3"
+
+ if [ $(ls -la "$dir/$service" | awk '{print $5}') -eq 0 ];
+ then
+ "./bare.sh" "$service" "$cmd" 2>&1 >/dev/null &
+ else
+ "$dir/$service" "$cmd" 2>&1 >/dev/null &
+ fi
+}
+
+doservice() {
+ cmd="$1"
+ service="$2"
+
+ if [ -z "${service}" ];
+ then
+ services=$(ls run)
+ for s in ${services};
+ do
+ runservice "$s" run "$cmd"
+ printf "%s: '%s' %s.\n" \
+ "$BASENAME" "$s" "$cmd"
+ done
+ else
+ if [ -x "avail/$service" ];
+ then
+ runservice "$service" avail "$cmd"
+ printf "%s: '%s' %s.\n" \
+ "$BASENAME" "$service" "$cmd"
+ else
+ printf "%s: '%s' is not available or executable.\n" \
+ "$BASENAME" "$service" >&2
+ exit 1
+ fi
+ fi
+}
+
+case "$1" in
+ -a)
+ if [ $# -gt 1 ] && [ -e "avail/$2" ];
+ then
+ ln -sf "../avail/$2" "run/$2"
+ printf "%s: '%s' activated.\n" \
+ "$BASENAME" "$2"
+ else
+ cd run
+ ls .
+ fi
+ ;;
+ -c)
+ [ -d "$BASEDIR" ] || mkdir -p "$BASEDIR"
+ [ -d "$BASEDIR/avail" ] || mkdir -p "$BASEDIR/avail"
+ [ -d "$BASEDIR/default" ] || mkdir -p "$BASEDIR/default"
+ [ -d "$BASEDIR/run" ] || mkdir -p "$BASEDIR/run"
+ ;;
+ -d)
+ if [ $# -gt 1 ] && [ -e "run/$2" ];
+ then
+ rm -f "run/$2"
+ printf "%s: '%s' deactivated.\n" \
+ "$BASENAME" "$2"
+ else
+ printf "%s: No service given or service is not marked as to run.\n" \
+ "$BASENAME" >&2
+ exit 1
+ fi
+ ;;
+ -k|-s)
+ doservice "$1" "$2"
+ ;;
+ -l)
+ cd avail
+ ls .
+ ;;
+ -r)
+ if [ $# -gt 1 ];
+ then
+ set -x
+ svc -k "$2"
+ svc -s "$2"
+ else
+ printf "%s: please give a service name.\n" \
+ "$BASENAME" >&2
+ exit 1
+ fi
+ ;;
+ *)
+ usage
+ ;;
+esac
diff --git a/bin/svc.d/avail/sdhcp b/bin/svc.d/avail/sdhcp
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+SERVICE="sdhcp"
+
+[ -e "/bin/svc.d/default/$SERVICE" ] && . "/bin/svc.d/default/$SERVICE"
+
+BIN="/bin/$SERVICE"
+
+PID=$(pidof -o %PPID $SERVICE)
+
+case $1 in
+ -s)
+ [ -z "$PID" ] && ifconfig $PARAMS up && $BIN $PARAMS;
+ ;;
+ -k)
+ [ -n "$PID" ] && kill -9 $PID &> /dev/null && ifconfig $PARAMS down
+ ;;
+ *)
+ echo "usage: $0 -s|-k"
+ exit 1
+esac
diff --git a/bin/svc.d/bare.sh b/bin/svc.d/bare.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+[ $# -eq 0 ] && SERVICE="$0"
+
+if [ $# -gt 0 ];
+then
+ SERVICE="$1"
+ shift 1
+fi
+
+[ -e "/bin/svc.d/default/$SERVICE" ] && . "/bin/svc.d/default/$SERVICE"
+
+BIN=""
+for p in /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin;
+do
+ if [ -x "$p/$SERVICE" ];
+ then
+ BIN="$p/$SERVICE"
+ break
+ fi
+done
+[ -z "$BIN" ] && exit 1
+
+PID=$(pidof -o %PPID $BIN)
+
+case $1 in
+ -s)
+ [ -z "$PID" ] && $BIN $PARAMS;
+ ;;
+ -k)
+ [ -n "$PID" ] && kill -9 $PID &> /dev/null;
+ ;;
+ *)
+ echo "usage: $0 -s|-k"
+ exit 1
+esac
+
diff --git a/bin/svc.d/default/sdhcp b/bin/svc.d/default/sdhcp
@@ -0,0 +1 @@
+PARAMS="eth0"