redis自己起動スクリプトの構成
Redisソースディレクトリの下にutilsフォルダがあり、install_が提供されています.server.shインストールツールは、自己起動のredisスクリプトを生成します.
実際の状況に応じてプロファイル、ログファイル、rdb/aofデータストレージディレクトリをそれぞれ記入する
スクリプトの内容は次のとおりです.
サービスを追加し、実行レベルを変更します.
[[email protected]]# cd utils/
[root@huntdb utils]# ./install_server.sh
Welcometo the redis service installer
Thisscript will help you easily set up a running redis server
Pleaseselect the redis port for this instance: [6379]
Selectingdefault: 6379
Pleaseselect the redis config file name [/etc/redis/6379.conf] /usr/local/redis/etc/redis.conf
Pleaseselect the redis log file name [/var/log/redis_6379.log] /usr/local/redis/log/redis.log
Pleaseselect the data directory for this instance [/var/lib/redis/6379] /usr/local/redis/data/
Pleaseselect the redis executable path [/usr/local/redis/bin/redis-server]
Selectedconfig:
Port : 6379
Configfile : /usr/local/redis/etc/redis.conf
Logfile :/usr/local/redis/log/redis.log
Datadir : /usr/local/redis/data/
Executable : /usr/local/redis/bin/redis-server
CliExecutable : /usr/local/redis/bin/redis-cli
Is thisok? Then press ENTER to go on or Ctrl-C to abort.
Copied/tmp/6379.conf => /etc/init.d/redis_6379
Installingservice...
Successfullyadded to chkconfig!
Successfullyadded to runlevels 345!
StartingRedis server...
Installationsuccessful!
実際の状況に応じてプロファイル、ログファイル、rdb/aofデータストレージディレクトリをそれぞれ記入する
スクリプトの内容は次のとおりです.
[root@huntdb utils]# cat /etc/init.d/redis_6379
#!/bin/sh
#Configurationsinjected by install_server below....
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/usr/local/redis/etc/redis.conf"
REDISPORT="6379"
###############
# SysVInit Information
#chkconfig: - 58 74
#description: redis_6379 is the redis daemon.
###BEGIN INIT INFO
#Provides: redis_6379
#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_6379
#Description: Redis daemon
### ENDINIT INFO
case"$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, processis already running or crashed"
else
echo "Starting Redisserver..."
$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 toshutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
status)
PID=$(cat $PIDFILE)
if [ ! -x /proc/${PID} ]
then
echo 'Redis is not running'
else
echo "Redis is running($PID)"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Please use start, stop,restart or status as first argument"
;;
esac
サービスを追加し、実行レベルを変更します.
[root@huntdb utils]# chkconfig --add redi_6379
[root@huntdb utils]# chkconfig --level redi_6379 35 on