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 rm -f "${PIDFILE}" echo"Redis stopped" fi ;; status) PID=$(cat $PIDFILE)
if ! kill -0 ${PID} > /dev/null 2>&1; 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
1 2 3 4 5 6 7
chmod +x ./redis_6379
## For Linux sudo cp ./redis_6379/etc/init.d/
## For OS X,因为没有 init.d 目录,故放在 /etc/redis 下 cp ./redis_6379/usr/local/etc/redis/redis_6379
Linux
开机启动
1 2 3 4 5
## For CentOS echo"/etc/init.d/redis_6379 start" | sudo tee --append/etc/rc.d/rc.local
## For Ubuntu sudo update-rc.d redis_6379 defaults