Skip to content

Instantly share code, notes, and snippets.

@13Cubed
Created February 20, 2016 04:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save 13Cubed/18b50d0ed20eb41a1439 to your computer and use it in GitHub Desktop.
This template can be used to create a service script for Red Hat Enterprise Linux. It will enable you to use “service myservice start”, “service myservice stop”, or “service myservice status” to control a particular process.
#!/bin/bash
# Replace myservice with your service name. Insert commands where noted.
# chkconfig: - 99 00
# Source function library.
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo -n "Starting myservice"
if [ -f /var/run/myservice.pid ]
then
echo
echo -n "myservice is already running!"
echo
exit 1
fi
# insert commands here ...
if [ -f /var/run/myservice.pid ]
then
echo_success
echo
else
echo_failure
echo
fi
;;
stop)
echo -n "Stopping myservice"
if [ ! -f /var/run/myservice.pid ]
then
echo
echo -n "myservice is not running!"
echo
exit 1
fi
# insert commands here ...
echo_success
echo
;;
status)
# insert commands here ...
;;
*)
echo "Usage: /sbin/service myservice {start|stop|status}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment