aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Luttringer <seblu@seblu.net>2011-04-02 12:39:05 +0200
committerTom Gundersen <teg@jklm.no>2011-04-16 09:31:37 +0800
commit2800e50847f3217b60eb07138c7f6fda05467616 (patch)
tree1be5c6a3bca957c3a9ccbd3cd00be871189034f1
parent95c20bbe2252bca6ea0d929f2930cd9cbe9f84bf (diff)
downloadinitscripts-2800e50847f3217b60eb07138c7f6fda05467616.tar.xz
Add an rc helper
This is allow a quick calling to /etc/rc.d scripts by calling a shell command. By example, starting sshd and gpm can be done by typing: rc start sshd gpm rc can also list available scripts and show which is started/stopped in DAEMONS [tomegun: fixed detection of autostart of background services] Signed-off-by: Sebastien Luttringer <seblu@seblu.net> Signed-off-by: Tom Gundersen <teg@jklm.no>
-rw-r--r--functions9
-rwxr-xr-xinstall.sh2
-rwxr-xr-xrc51
3 files changed, 62 insertions, 0 deletions
diff --git a/functions b/functions
index 2c3a6d5..fd0928e 100644
--- a/functions
+++ b/functions
@@ -175,6 +175,15 @@ have_daemon() {
[[ -f /etc/rc.d/$1 && -x /etc/rc.d/$1 ]]
}
+# Check if $1 is started at boot
+ck_autostart() {
+ local d
+ for d in "${DAEMONS[@]}"; do
+ [[ "$1" = ${d#@} ]] && return 1
+ done
+ return 0
+}
+
start_daemon() {
have_daemon "$1" && /etc/rc.d/"$1" start
}
diff --git a/install.sh b/install.sh
index 8e6c3d7..c70a10e 100755
--- a/install.sh
+++ b/install.sh
@@ -21,3 +21,5 @@ done
gcc $CFLAGS -o minilogd minilogd.c || exit 1
install -D -m755 minilogd ${DESTDIR}/sbin/minilogd || exit 1
+
+install -D -m755 rc ${DESTDIR}/sbin/rc || exit 1
diff --git a/rc b/rc
new file mode 100755
index 0000000..4bb9730
--- /dev/null
+++ b/rc
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+. /etc/rc.conf
+. /etc/rc.d/functions
+
+usage() {
+ cat >&2 << EOF
+usage: rc action daemon ...
+
+e.g: rc list
+ rc help
+ rc start sshd gpm
+EOF
+}
+
+(( $# < 1 )) && usage && exit 1
+
+case $1 in
+ help)
+ usage
+ ;;
+ list)
+ cd /etc/rc.d/
+ for d in *; do
+ have_daemon "$d" || continue
+ # print running / stopped satus
+ if ! ck_daemon "$d"; then
+ printf "${C_OTHER}[${C_DONE}STARTED${C_OTHER}]"
+ else
+ printf "${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]"
+ fi
+ # print auto / manual status
+ if ! ck_autostart "$d"; then
+ printf "${C_OTHER}[${C_DONE}AUTO${C_OTHER}]"
+ else
+ printf "${C_OTHER}[${C_FAIL} ${C_OTHER}]"
+ fi
+ printf " ${C_MAIN}$d${C_CLEAR}\n"
+ done
+ ;;
+ *)
+ action=$1
+ shift
+ for i; do
+ [[ -x "/etc/rc.d/$i" ]] && "/etc/rc.d/$i" $action
+ done
+esac
+
+true
+
+# vim: set ts=2 sw=2 noet: