Skip to content

Instantly share code, notes, and snippets.

@netkiller
Created June 27, 2014 14:50
Show Gist options
  • Save netkiller/7f2aea36add065fad8f4 to your computer and use it in GitHub Desktop.
Save netkiller/7f2aea36add065fad8f4 to your computer and use it in GitHub Desktop.
Shell Daemon start | stop | restart | status
$ cat schedule.sh
#!/bin/bash
##############################################
# $Author: netkiller $
# $Id: shell.xml 449 2012-08-10 10:38:08Z netkiller $
# http://netkiller.github.io
##############################################
NAME=schedule
BASEDIR='/www'
PROG=$(basename $0)
LOGFILE=/var/tmp/$NAME.log
PIDFILE=/var/tmp/$NAME.pid
##############################################
PHP="/srv/php/bin/php -c /srv/php/etc/php.cli.ini"
##############################################
#echo $$
#echo $BASHPID
cd $BASEDIR
function run(){
#$PHP test.php
#>> $LOGFILE
sleep 60
}
function start(){
if [ -f "$PIDFILE" ]; then
echo $PIDFILE
exit 2
fi
for (( ; ; ))
do
run
done &
echo $! > $PIDFILE
}
function stop(){
[ -f $PIDFILE ] && kill `cat $PIDFILE` && rm -rf $PIDFILE
}
function status(){
ps ax | grep $PROG | grep -v grep | grep -v status
}
function reset(){
pkill $PROG
[ -f $PIDFILE ] && rm -rf $PIDFILE
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
reset)
reset
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reset}"
exit 2
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment