Skip to content

Instantly share code, notes, and snippets.

@ac-astuartkregor
Last active July 26, 2019 05:23
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ac-astuartkregor/5d11fe0e9f028087b66ac90423293263 to your computer and use it in GitHub Desktop.
Save ac-astuartkregor/5d11fe0e9f028087b66ac90423293263 to your computer and use it in GitHub Desktop.
A generic Centos init script for redis
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis/redis.pid
# This init script assumes daemonize is set to yes in the redis config
redis="/usr/bin/redis-server"
prog=$(basename $redis)
PID_FILE="/var/run/redis/redis.pid"
REDIS_CONF_FILE="/etc/redis.conf"
[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis
lockfile=/var/lock/subsys/redis
start() {
[ -x $redis ] || exit 5
[ -f $REDIS_CONF_FILE ] || (echo "Missing config file at $REDIS_CONF_FILE" && exit 6)
echo "Starting $prog: with config $REDIS_CONF_FILE"
$redis $REDIS_CONF_FILE
retval=$?
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
kill -s QUIT $(cat $PID_FILE)
retval=$?
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
status_q() {
[ -f $PID_FILE ] || return 1
kill -s 0 $(cat $PID_FILE)
return $?
}
restart() {
stop
echo
start
}
case "$1" in
start)
status_q && exit 0
$1
;;
stop)
status_q || exit 0
$1
;;
restart)
$1
;;
status)
status_q && echo "Redis is running with PID $(cat $PID_FILE)" && exit 0
echo "Redis is not running"
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment