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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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