I am trying to set init.d script for some service - let it be uptime that is located in /usr/bin/uptime. Here is my script:
#!/bin/bash
# description: read service
#Source function library
. /etc/rc.d/init.d/functions
RETVAL=0
UPTIME=/usr/bin/uptime
PIDFILE=/var/run/read.pid
start() {
echo -n $"Starting $UPTIME service: "
/usr/bin/uptime &
echo $! > $PIDFILE;
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/uptime
echo
return $RETVAL
}
stop() {
echo -n $"Shutdown $UPTIME service: "
killproc /usr/bin/uptime
rm -f $PIDFILE
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/uptime
echo
return $RETVAL
}
restart() {
echo -n $"Restarting $UPTIME service: "
killproc /usr/bin/uptime
/usr/bin/uptime &
}
status() {
if [ `pidof /var/run/read.pid` ];then
echo "Running"
else
echo "Not running"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status /usr/bin/uptime
;;
restart|reload)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit $?
After starting my script PIDFILE=/var/run/read.pid
had successfully created. But when I used status
for my service - it was not running. It meant that pidof /var/run/read.pid
didn't find pid of my service. ps -ef
didn't show anything too. What am I going to do to make my read service runs in background properly and my status
command /etc/init.d/read.sh status
shows running
due to my script.