Skip to content

Instantly share code, notes, and snippets.

@faberyx
Last active December 21, 2021 20:00
Show Gist options
  • Save faberyx/31fd518d409cc8d023b916c277dc30f5 to your computer and use it in GitHub Desktop.
Save faberyx/31fd518d409cc8d023b916c277dc30f5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# myapp daemon
# chkconfig: 345 20 80
# description: myapp daemon
# processname: myapp
. /etc/init.d/functions
D_PATH="/home/fabry/Documents/service_test/"
D_NAME=srv_test
USER=root
PID_FILE=/var/run/$D_NAME.pid
LOCK_FILE=/var/lock/subsys/$D_NAME
RETVAL=0
case "$1" in
start)
printf "%-50s" "Starting $NAME..."
daemon --user $USER --pidfile $PID_FILE $D_PATH$D_NAME
RETVAL=$?
echo
#If all is well touch the lock and pid file
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
[ $RETVAL -eq 0 ] && touch $PID_FILE
return $RETVAL
;;
status)
printf "%-50s" "Checking $NAME..."
status $PID_FILE
;;
stop)
printf "%-50s" "Stopping $NAME"
killproc $D_PATH$D_NAME
RETVAL=$?
echo
#If all is well remove the lockfile
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
[ $RETVAL -eq 0 ] && rm -f $PID_FILE
return $RETVAL
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {status|start|stop|restart}"
exit 1
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment