#!/bin/sh # # dhcdbd daemon # PIDFILE=/var/run/dhcdbd.pid; dhcdbd_start() { # Just in case the pidfile is still there, we need to nuke it. if [ -e "$PIDFILE" ]; then rm -f $PIDFILE fi echo "Starting dhcdbd daemon: /sbin/dhcdbd --system" /sbin/dhcdbd --system &>/dev/null; } dhcdbd_status() { local pidlist=`cat $PIDFILE 2>/dev/null` if [ -z "$pidlist" ]; then return 1 fi local command=`ps -p $pidlist -o comm=` if [ "$command" != 'dhcdbd' ]; then return 1 fi } dhcdbd_stop() { echo -en "Stopping dhcdbd daemon: "; dbus-send --system --dest=com.redhat.dhcp --type=method_call \ --print-reply --reply-timeout=20000 /com/redhat/dhcp \ com.redhat.dhcp.quit > /dev/null 2>&1 local pidlist=`cat $PIDFILE 2>/dev/null` if [ ! -z "$pidlist" ]; then kill $pidlist &>/dev/null rm -f $PIDFILE &>/dev/null fi echo "stopped"; } dhcdbd_restart() { dhcdbd_stop sleep 1 dhcdbd_start } case "$1" in 'start') if ( ! dhcdbd_status ); then dhcdbd_start else echo "dhcdbd is already running (will not start it twice)." fi ;; 'stop') dhcdbd_stop; ;; 'restart') dhcdbd_restart; ;; 'status') if ( dhcdbd_status ); then echo "dhcdbd is currently running" else echo "dhcdbd bus is not running." fi ;; *) echo "usage $0 start|stop|status|restart"; esac