2015-06-15 14:20:51 +02:00
|
|
|
Index: utils/redis_init_script
|
|
|
|
===================================================================
|
|
|
|
--- utils/redis_init_script.orig
|
|
|
|
+++ utils/redis_init_script
|
2018-06-15 12:39:49 +02:00
|
|
|
@@ -1,50 +1,133 @@
|
2011-10-24 12:48:58 +02:00
|
|
|
#!/bin/sh
|
2018-06-15 12:39:49 +02:00
|
|
|
-#
|
|
|
|
-# Simple Redis init.d script conceived to work on Linux systems
|
|
|
|
-# as it does use of the /proc filesystem.
|
|
|
|
|
2012-11-20 13:09:48 +01:00
|
|
|
+# System startup script for Redis for OpenSUSE >= 11.4
|
|
|
|
+#
|
|
|
|
+# Author: Marcello Barnaba <m.barnaba@ifad.org>
|
|
|
|
+# Tue Jul 31 17:32:27 CEST 2012
|
|
|
|
+#
|
|
|
|
+# LSB-compatible service control script; see http://www.linuxbase.org/spec/
|
|
|
|
+# Install it in /etc/init.d/redis and run insserv /etc/init.d/redis
|
|
|
|
+# Define configurations in /etc/init.d/redis/NAME.conf
|
|
|
|
+#
|
|
|
|
+# Source: https://gist.github.com/804026
|
2018-06-15 12:39:49 +02:00
|
|
|
+#
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
-# Provides: redis_6379
|
|
|
|
-# Default-Start: 2 3 4 5
|
|
|
|
-# Default-Stop: 0 1 6
|
|
|
|
-# Short-Description: Redis data structure server
|
|
|
|
-# Description: Redis data structure server. See https://redis.io
|
2011-10-24 12:48:58 +02:00
|
|
|
+# Provides: redis
|
|
|
|
+# Required-Start: $syslog $remote_fs
|
|
|
|
+# Required-Stop: $syslog $remote_fs
|
2012-11-20 13:09:48 +01:00
|
|
|
+# Default-Start: 3 5
|
2011-10-24 12:48:58 +02:00
|
|
|
+# Default-Stop: 0 1 2 6
|
|
|
|
+# Short-Description: Redis server
|
2012-11-20 13:09:48 +01:00
|
|
|
+# Description: Starts and stops the configured Redis instances
|
2018-06-15 12:39:49 +02:00
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
-REDISPORT=6379
|
|
|
|
-EXEC=/usr/local/bin/redis-server
|
|
|
|
-CLIEXEC=/usr/local/bin/redis-cli
|
2012-11-20 13:09:48 +01:00
|
|
|
+EXEC=/usr/sbin/redis-server
|
|
|
|
+USER=redis
|
|
|
|
+STATE=/var/run/redis
|
|
|
|
+CONF=/etc/redis
|
|
|
|
+
|
2011-10-24 12:48:58 +02:00
|
|
|
+. /etc/rc.status
|
2012-11-20 13:09:48 +01:00
|
|
|
+
|
|
|
|
+if [ ! -d $STATE ]; then
|
|
|
|
+ install -d $state -o $USER -g $USER -m 0755 $STATE
|
|
|
|
+fi
|
|
|
|
+
|
|
|
|
+_get_env() {
|
|
|
|
+ INSTANCE=$1
|
|
|
|
+ PIDFILE=${STATE}/${INSTANCE}.pid
|
|
|
|
+ CONFIG=${CONF}/${INSTANCE}.conf
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+_foreach_config() {
|
|
|
|
+ command=$1
|
|
|
|
+
|
|
|
|
+ if [ -n "$2" ]; then
|
|
|
|
+ $command $2
|
|
|
|
+ else
|
|
|
|
+ for file in /etc/redis/*.conf; do
|
2012-11-20 15:14:50 +01:00
|
|
|
+ $command `basename "$file" .conf`
|
2012-11-20 13:09:48 +01:00
|
|
|
+ done
|
|
|
|
+ fi
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+start() {
|
|
|
|
+ _get_env $1
|
|
|
|
+
|
|
|
|
+ echo -n "Starting Redis server '${INSTANCE}'... "
|
|
|
|
+
|
|
|
|
+ if [ ! -f ${CONFIG} ]; then
|
|
|
|
+ echo "$CONFIG not found"
|
|
|
|
+ rc_failed
|
2018-06-15 12:39:49 +02:00
|
|
|
+
|
2012-11-20 13:09:48 +01:00
|
|
|
+ elif [ -f ${PIDFILE} ] && [ -x /proc/`cat ${PIDFILE}` ]; then
|
|
|
|
+ echo -n "already running (PID `cat ${PIDFILE}`)"
|
|
|
|
+
|
|
|
|
+ else
|
|
|
|
+ rm -f ${PIDFILE}
|
|
|
|
+ sudo -u $USER $EXEC $CONFIG
|
|
|
|
+ fi
|
|
|
|
+ rc_status -v
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+stop() {
|
|
|
|
+ _get_env $1
|
|
|
|
+
|
|
|
|
+ echo -n "Stopping Redis server '${INSTANCE}' ... "
|
|
|
|
+
|
|
|
|
+ if [ ! -f $PIDFILE ]; then
|
|
|
|
+ echo -n "not running"
|
|
|
|
+ else
|
|
|
|
+ PID=`cat $PIDFILE`
|
|
|
|
+ CLI='/usr/bin/redis-cli'
|
|
|
|
+ PASS=`grep ^requirepass $CONFIG | awk '{print $2}'`
|
|
|
|
+ PORT=`grep ^port $CONFIG | awk '{print $2}'`
|
2015-06-15 14:20:51 +02:00
|
|
|
+ BIND=`grep ^bind $CONFIG | awk '{print $2}'`
|
2012-11-20 13:09:48 +01:00
|
|
|
+
|
|
|
|
+ CLI="$CLI -p $PORT"
|
|
|
|
+ [ -n "$PASS" ] && CLI="$CLI -a $PASS"
|
2015-06-15 14:20:51 +02:00
|
|
|
+ [ -n "$BIND" ] && CLI="$CLI -h $BIND"
|
2012-11-20 13:09:48 +01:00
|
|
|
+
|
|
|
|
+ $CLI shutdown
|
|
|
|
+ echo -n "Waiting... "
|
|
|
|
+
|
|
|
|
+ while [ -x /proc/${PID} ]; do
|
|
|
|
+ sleep 1
|
|
|
|
+ echo -n '.'
|
|
|
|
+ done
|
|
|
|
+ rm -f ${PIDFILE}
|
|
|
|
+ fi
|
|
|
|
+ rc_status -v
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+status() {
|
|
|
|
+ _get_env $1
|
|
|
|
+
|
|
|
|
+ echo -n "Checking for redis '${INSTANCE}'"
|
|
|
|
+ /sbin/checkproc -p $PIDFILE $EXEC
|
|
|
|
+ rc_status -v
|
|
|
|
+}
|
2011-10-24 12:48:58 +02:00
|
|
|
|
|
|
|
-PIDFILE=/var/run/redis_${REDISPORT}.pid
|
|
|
|
-CONF="/etc/redis/${REDISPORT}.conf"
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
- if [ -f $PIDFILE ]
|
|
|
|
- then
|
|
|
|
- echo "$PIDFILE exists, process is already running or crashed"
|
|
|
|
- else
|
|
|
|
- echo "Starting Redis server..."
|
|
|
|
- $EXEC $CONF
|
2012-11-20 13:09:48 +01:00
|
|
|
- fi
|
|
|
|
- ;;
|
|
|
|
+ _foreach_config start $2
|
|
|
|
+ ;;
|
|
|
|
+
|
2011-10-24 12:48:58 +02:00
|
|
|
stop)
|
2012-11-20 13:09:48 +01:00
|
|
|
- if [ ! -f $PIDFILE ]
|
|
|
|
- then
|
2011-10-24 12:48:58 +02:00
|
|
|
- echo "$PIDFILE does not exist, process is not running"
|
2012-11-20 13:09:48 +01:00
|
|
|
- else
|
2011-10-24 12:48:58 +02:00
|
|
|
- PID=$(cat $PIDFILE)
|
|
|
|
- echo "Stopping ..."
|
2012-11-20 13:09:48 +01:00
|
|
|
- $CLIEXEC -p $REDISPORT shutdown
|
2011-10-24 12:48:58 +02:00
|
|
|
- while [ -x /proc/${PID} ]
|
2012-11-20 13:09:48 +01:00
|
|
|
- do
|
2011-10-24 12:48:58 +02:00
|
|
|
- echo "Waiting for Redis to shutdown ..."
|
2012-11-20 13:09:48 +01:00
|
|
|
- sleep 1
|
|
|
|
- done
|
2011-10-24 12:48:58 +02:00
|
|
|
- echo "Redis stopped"
|
2012-11-20 13:09:48 +01:00
|
|
|
- fi
|
|
|
|
- ;;
|
|
|
|
+ _foreach_config stop $2
|
|
|
|
+ ;;
|
|
|
|
+
|
2011-10-24 12:48:58 +02:00
|
|
|
+ status)
|
2012-11-20 13:09:48 +01:00
|
|
|
+ _foreach_config status $2
|
|
|
|
+ ;;
|
|
|
|
+
|
|
|
|
+ restart)
|
|
|
|
+ $0 stop $2
|
|
|
|
+ $0 start $2
|
|
|
|
+ ;;
|
|
|
|
+
|
|
|
|
*)
|
|
|
|
- echo "Please use start or stop as first argument"
|
|
|
|
- ;;
|
|
|
|
+ echo "Usage: $0 <start|stop|restart|status>"
|
2011-10-24 12:48:58 +02:00
|
|
|
+ exit 1
|
2012-11-20 13:09:48 +01:00
|
|
|
+ ;;
|
2011-10-24 12:48:58 +02:00
|
|
|
esac
|