一、shell脚本
#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
port=6379
bin=/home/redis-5.0.4/src/redis-server
config=/home/redis-5.0.4/redis.conf
pid=/var/run/redis_6379.pid
auth=woaini
cli=/home/redis-5.0.4/src/redis-cli
case "$1" in
start)
if [-f $pid]
then
echo "$pid exists, process is already running or crashed"
else
echo "Starting Redis server..."
$bin $config
fi
;;
stop)
if [ ! -f $pid ]
then
echo echo "$pid does not exist, process is not running"
else
systempid=$(cat $pid)
echo "Stopping......"
#$CLI -h $BIND_IP -a $AUTH -p $REDISPORT SHUTDOWN
$cli -a $auth -p $port shutdown
while [ -x /proc/${systempid} ]
do
echo "Waiting for redis to shutdown..."
sleep 1
done
echo "Redis stopped."
fi
;;
restart|reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|status|start}" >&2
exit 1
esac把上述代码存为redis,放到/etc/init.d/下,文件名取redis
chmod +x /etc/init.d/redis chkconfig --add redis chkconfig redis on
文件上面的chkconfig的注释必须添加,否则会报错service redis does not support chkconfig
# chkconfig: 2345 90 10 # description: Redis is a persistent key-value database

fffffasdfasdfasdfasdfas;kdfjlaskl;dfjaskl;dfjakls;dfjkal;sfdjlaks;df als;dfj awkls;dfj asl;dfj aslk;dfjaskl;dfjas;ldf
访客评论