Linux sets the startup method of Redis boot
- 2020-05-27 07:31:48
- OfStack
1. Setup method under CentOS 7.0 system
Assume Redis is installed, version 3.2.4
#cd redis-3.2.4
#mkdir /etc/redis
#cp redis.conf /etc/redis/6379.conf
#cp utils/redis_init_script /etc/init.d/redis
#chmod a+x /etc/init.d/redis
#cp src/redis-server /usr/local/bin/
#cp src/redis-cli /usr/local/bin/
#vim /etc/init.d/redis
Add in the script file
#chkconfig: 2345 80 90
Otherwise, an error will appear that "redis services do not support chkconfig"
#!/bin/sh
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
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
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
Register the event and boot up
#chkconfig redis on
Start the service
#service redis start
See if the service is started
#lsof -i:6379
2. Debian 8.0 setting method
The steps are similar, but Debian USES them
update-rc.d
(or insserv) instead of chkconfig
The script file description is also different.
Assume Redis is installed, version 3.2.4
#cd redis-3.2.4
#mkdir /etc/redis
#cp redis.conf /etc/redis/6379.conf
#cp utils/redis_init_script /etc/init.d/redis
#chmod a+x /etc/init.d/redis
#cp src/redis-server /usr/local/bin/
#cp src/redis-cli /usr/local/bin/
#vim /etc/init.d/redis
Add in the script file
### BEGIN INIT INFO
# Provides: redis6379
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis6379
# Description: penavico redis 6379
### END INIT INFO
Otherwise it will happen
“ insserv: warning: script ‘redis6379′ missing LSB tags and overrides”
Error prompt
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
### BEGIN INIT INFO
# Provides: redis6379
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis6379
# Description: penavico redis 6379
### END INIT INFO
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
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
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
Register the event and boot up
#update-rc.d redisd defaults
Start the service
#service redis start
See if the service is started
#!/bin/sh
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
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
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
0
After startup, the default configuration file location: / etc/redis / 6379. conf
conclusion