#!/bin/sh # # lirc: lirc daemon # # description: This is a daemon for automatically activate lirc. # # processname: lircd # pidfile: /var/run/lirc/lircd # prefix=/usr exec_prefix=/usr sbindir=${exec_prefix}/sbin LIRC_BIN=${sbindir}/lircd # Sanity checks. [ -x $LIRC_BIN ] || exit 0 PIDFILE=/var/run/lirc/lircd.pid lirc_start() { if [ "`pgrep dbus-daemon`" = "" ]; then echo "D-BUS must be running to start lircd" return fi if [ "`pgrep hald`" = "" ]; then echo "HAL must be running to start lircd" return fi # Just in case the pidfile is still there, we may need to nuke it. if [ -e "$PIDFILE" ]; then rm -f $PIDFILE fi echo "Starting lircd daemon: $LIRC_BIN" $LIRC_BIN } lirc_status() { local pidlist=`cat $PIDFILE 2>/dev/null` if [ -z "$pidlist" ]; then return 1 fi local command=`ps -p $pidlist -o comm=` if [ "$command" != 'lircd' ]; then return 1 fi } lirc_stop() { echo -en "Stopping lircd: " local pidlist=`cat $PIDFILE 2>/dev/null` if [ ! -z "$pidlist" ]; then kill $pidlist &>/dev/null rm -f $PIDFILE &>/dev/null fi echo "stopped"; } lirc_restart() { lirc_stop lirc_start } case "$1" in 'start') if ( ! lirc_status ); then lirc_start else echo "lircd is already running (will not start it twice)." fi ;; 'stop') lirc_stop ;; 'restart') lirc_restart ;; 'status') if ( lirc_status ); then echo "lircd is currently running" else echo "lircd is not running." fi ;; *) echo "usage $0 start|stop|status|restart" esac