Share a script that can configure the Redis database to boot automatically
At first want to put order redis-server/etc/redis/redis.conf join to/etc/rc.d/rc.local unexpectedly not, had to find another way
The first step is to write the main service boot SH script/etc/init.d/redis
The code is as follows |
Copy Code |
#!/bin/bash # # Redis-this script starts and stops the Redis-server daemon # # Chkconfig:-80 12 # Description:redis is a persistent key-value database # Processname:redis-server # config:/etc/6379.conf # Pidfile:/redis/redis6379.pid Path=/usr/local/bin:/sbin:/usr/bin:/bin
redisport=6379 Ex_ec=/usr/local/bin/redis-server Redis_cli=/usr/local/bin/redis-cli
Pidfile=/redis/redis6379.pid conf= "/etc/6379.conf"
Case "$" in Start If [f $PIDFILE] Then echo "$PIDFILE exists, process is already running or crashed" Else echo "Starting Redis server ..." $EX _ec $CONF Fi If ["$?" = "0"] Then echo "Redis is running ..." Fi ;; Stop if [!-F $PIDFILE] Then echo "$PIDFILE does not exist, process isn't running" Else pid=$ (Cat $PIDFILE) echo "Stopping ..." $REDIS _cli-p $REDISPORT SHUTDOWN While [-X ${pidfile}] Todo echo "Waiting for Redis to shutdown ..." Sleep 1 Done echo "Redis stopped" Fi ;; Restart|force-reload) ${0} stop ${0} start ;; *) echo "Usage:/etc/init.d/redis {start|stop|restart|force-reload}" >&2 Exit 1 Esac |
File deposited in/etc/init.d/redis
Then modify the permissions and Chkconfig
chmod 0777/etc/init.d/redis
Chkconfig Redis on
Join to boot boot vi/etc/rc.d/rc.local
Add the following 2 lines
Service Redis Start
Done