Last active
January 30, 2020 05:21
-
-
Save vinceyuan/9667435 to your computer and use it in GitHub Desktop.
Init script to start/stop redis-server for CentOS or amazon ec2 linux ami. You can run multiple redis-server on one server with this script. Just copy and replace 'per-project' with your project name in this file for each project.
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/sh | |
# From - http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/ | |
# | |
# redis - this script starts and stops the redis-server daemon | |
# Originally from - https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server | |
# Modified by Vince Yuan https://gist.github.com/vinceyuan/9667435 | |
# | |
# chkconfig: - 85 15 | |
# description: Redis is a persistent key-value database | |
# processname: redis-server | |
# config: /etc/redis/redis-per-project.conf | |
# config: /etc/sysconfig/redis-per-project | |
# pidfile: /var/run/redis-per-project.pid | |
# Source function library. | |
. /etc/rc.d/init.d/functions | |
# Source networking configuration. | |
. /etc/sysconfig/network | |
# Check that networking is up. | |
[ "$NETWORKING" = "no" ] && exit 0 | |
redis="/usr/local/bin/redis-server" | |
prog=$(basename $redis) | |
REDIS_CONF_FILE="/etc/redis/redis-per-project.conf" | |
PIDFILE="/var/run/redis-per-project.pid" | |
[ -f /etc/sysconfig/redis-per-project ] && . /etc/sysconfig/redis-per-project | |
lockfile=/var/lock/subsys/redis-per-project | |
start() { | |
[ -x $redis ] || exit 5 | |
[ -f $REDIS_CONF_FILE ] || exit 6 | |
echo -n $"Starting $prog: " | |
daemon --pidfile=$PIDFILE $redis $REDIS_CONF_FILE | |
retval=$? | |
echo | |
[ $retval -eq 0 ] && touch $lockfile | |
return $retval | |
} | |
stop() { | |
echo -n $"Stopping $prog: " | |
killproc -p $PIDFILE $prog -QUIT | |
retval=$? | |
echo | |
[ $retval -eq 0 ] && rm -f $lockfile $PIDFILE | |
return $retval | |
} | |
restart() { | |
stop | |
start | |
} | |
reload() { | |
echo -n $"Reloading $prog: " | |
killproc -p $PIDFILE $redis -HUP | |
RETVAL=$? | |
echo | |
} | |
force_reload() { | |
restart | |
} | |
rh_status() { | |
status -p $PIDFILE $redis | |
} | |
rh_status_q() { | |
rh_status >/dev/null 2>&1 | |
} | |
case "$1" in | |
start) | |
rh_status_q && exit 0 | |
$1 | |
;; | |
stop) | |
#rh_status_q || exit 0 | |
$1 | |
;; | |
restart|configtest) | |
$1 | |
;; | |
reload) | |
rh_status_q || exit 7 | |
$1 | |
;; | |
force-reload) | |
force_reload | |
;; | |
status) | |
rh_status | |
;; | |
condrestart|try-restart) | |
rh_status_q || exit 0 | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" | |
exit 2 | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment