脚本内容如下;
#!/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/redis/redis.conf# pidfile: /var/run/redis.pid source/etc/init.d/functions BIN="/usr/local/bin"CONFIG="/etc/redis/redis.conf"PIDFILE="/var/run/redis.pid" ### Read configuration[-r"$SYSCONFIG"]&&source"$SYSCONFIG" RETVAL=0prog="redis-server"desc="Redis Server" start(){ if[-e$PIDFILE];thenecho"$desc already running...."exit1fi echo-n $"Starting $desc: " daemon $BIN/$prog$CONFIG RETVAL=$?echo[$RETVAL-eq0]&&touch/var/lock/subsys/$progreturn$RETVAL} stop(){echo-n $"Stop $desc: " killproc $progRETVAL=$?echo[$RETVAL-eq0]&&rm-f/var/lock/subsys/$prog$PIDFILEreturn$RETVAL} restart(){ stop start } case"$1"in start) start ;; stop) stop ;; restart) restart ;; condrestart)[-e/var/lock/subsys/$prog]&& restart RETVAL=$?;; status) status $progRETVAL=$?;;*)echo $"Usage: $0 {start|stop|restart|condrestart|status}"RETVAL=1esac exit$RETVAL
下载脚本:艺搜下载
将下载下来的脚本放在/etc/init.d/目录下
- 更改脚本权限
chmod 777 /etc/init.d/redis
- 测试
service redis start