Skip to content

Instantly share code, notes, and snippets.

@13Cubed 13Cubed/service
Created Feb 20, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.