Last active
February 3, 2016 14:37
-
-
Save vovanbo/ee3ac222bad4bc7e0498 to your computer and use it in GitHub Desktop.
Proper /etc/init.d/redis script of Redis on socket in Ubuntu
This file contains hidden or 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 | |
#Configurations injected by install_server below.... | |
EXEC=/usr/local/bin/redis-server | |
CLIEXEC=/usr/local/bin/redis-cli | |
PIDFILE=/var/run/redis_6379.pid | |
CONF=/etc/redis/6379.conf | |
REDISPORT=6379 | |
REDISSOCKET=/var/run/redis_6379.sock | |
SOCKET_USER=www-data | |
SOCKET_GROUP=webdev | |
############### | |
# SysV Init Information | |
# chkconfig: - 58 74 | |
# description: redis_XXXX is the redis daemon. | |
### BEGIN INIT INFO | |
# Provides: redis_XXXX | |
# Required-Start: $network $local_fs $remote_fs | |
# Required-Stop: $network $local_fs $remote_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Should-Start: $syslog $named | |
# Should-Stop: $syslog $named | |
# Short-Description: start and stop redis_XXXX | |
# Description: Redis daemon | |
### END INIT INFO | |
case "$1" in | |
start) | |
if [ -f $PIDFILE ] | |
then | |
echo "$PIDFILE exists, process is already running or crashed" | |
mv $PIDFILE $PIDFILE_$(date +"%Y%m%d") | |
else | |
echo "Starting Redis server..." | |
$EXEC $CONF | |
if [ ! -z "$REDISSOCKET" ] | |
then | |
while [ ! -e $REDISSOCKET ] | |
do | |
echo "Waiting for Redis to start ..." | |
sleep 1 | |
done | |
chown $SOCKET_USER:$SOCKET_GROUP $REDISSOCKET && chmod ug+w $REDISSOCKET | |
fi | |
fi | |
;; | |
stop) | |
if [ ! -f $PIDFILE ] | |
then | |
echo "$PIDFILE does not exist, process is not running" | |
else | |
PID=$(cat $PIDFILE) | |
echo "Stopping ..." | |
if [ -e $REDISSOCKET ] | |
then | |
$CLIEXEC -s $REDISSOCKET shutdown | |
else | |
$CLIEXEC -p $REDISPORT shutdown | |
fi | |
while [ -x /proc/${PID} ] | |
do | |
echo "Waiting for Redis to shutdown ..." | |
sleep 1 | |
done | |
echo "Redis stopped" | |
fi | |
;; | |
status) | |
if [ ! -f $PIDFILE ] | |
then | |
echo 'Redis is not running' | |
else | |
echo "Redis is running ($(<$PIDFILE))" | |
fi | |
;; | |
restart) | |
$0 stop | |
$0 start | |
;; | |
*) | |
echo "Please use start, stop, restart or status as first argument" | |
;; | |
esac |
👍 ( I don't get it why redis isn't implementing the same by default )
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this gist solved issue with socket's owner and group. Also added checking for socket or TCP configuration.