Hostinfo day 6: RPM packaging, initscripts, hostinfo-status, hostinfo-test.
[virt-hostinfo.git] / conf / hostinfo.init.in
diff --git a/conf/hostinfo.init.in b/conf/hostinfo.init.in
new file mode 100644 (file)
index 0000000..20b1ae0
--- /dev/null
@@ -0,0 +1,111 @@
+#!/bin/sh
+#
+# hostinfo: Access host information and statistics from virtual machines
+#
+# chkconfig:   - 98 02
+# description: This daemon allows access to host information from guests.
+
+### BEGIN INIT INFO
+# Provides: hostinfo
+# Required-Start: libvirtd
+# Required-Stop: libvirtd
+# Default-Stop: 
+# Short-Description: Access host information and statistics from virtual machines
+# Description: This daemon allows access to host information from guests.
+### END INIT INFO
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+exec="/usr/sbin/hostinfod"
+prog="hostinfod"
+config="/etc/hostinfo/hostinfo.conf"
+
+[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+ARGS=
+if [ -n "$HOSTINFO_VERBOSE" ]; then
+    ARGS="$ARGS -v"
+fi
+if [ -n "$HOSTINFO_CONFIG" ]; then
+    ARGS="$ARGS --config $HOSTINFO_CONFIG"
+fi
+if [ -n "$HOSTINFO_LIBVIRT_URI" ]; then
+    ARGS="$ARGS --connect $HOSTINFO_LIBVIRT_URI"
+fi
+
+lockfile=/var/lock/subsys/$prog
+
+start() {
+    [ -x $exec ] || exit 5
+    [ -f $config ] || exit 6
+    echo -n $"Starting $prog: "
+    daemon $exec $ARGS
+    retval=$?
+    echo
+    [ $retval -eq 0 ] && touch $lockfile
+    return $retval
+}
+
+stop() {
+    echo -n $"Stopping $prog: "
+    killproc $prog
+    retval=$?
+    echo
+    [ $retval -eq 0 ] && rm -f $lockfile
+    return $retval
+}
+
+restart() {
+    stop
+    start
+}
+
+reload() {
+    restart
+}
+
+force_reload() {
+    restart
+}
+
+rh_status() {
+    status $prog
+}
+
+rh_status_q() {
+    rh_status >/dev/null 2>&1
+}
+
+
+case "$1" in
+    start)
+        rh_status_q && exit 0
+        $1
+        ;;
+    stop)
+        rh_status_q || exit 0
+        $1
+        ;;
+    restart)
+        $1
+        ;;
+    reload)
+        rh_status_q || exit 7
+        $1
+        ;;
+    force-reload)
+        force_reload
+        ;;
+    status)
+        rh_status
+        ;;
+    condrestart|try-restart)
+        rh_status_q || exit 0
+        restart
+        ;;
+    *)
+        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
+        exit 2
+esac
+exit $?