编写脚本文件
#!/bin/bash
#chkconfig: 22345 10 90
#description: Start and Stop redis
REDISPORT=6379
EXEC=/usr/local/soft/redis5/bin/redis-server
CLIEXEC=/usr/local/soft/redis5/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/usr/local/soft/redis5/conf/redis.conf"
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
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart)
"$0" stop
sleep 3
"$0" start
;;
*)
echo "Please use start or stop or restart as first argument"
;;
esac
操作步骤记录
[root@localhost redis5]# vim /etc/init.d/redis5
[root@localhost redis5]# chmod +x /etc/init.d/redis5
[root@localhost redis5]#
[root@localhost redis5]#
[root@localhost redis5]# chkconfig --add redis5
[root@localhost redis5]#
[root@localhost redis5]#
[root@localhost redis5]#
[root@localhost redis5]#
[root@localhost redis5]# chkconfig redis on
error reading information on service redis: No such file or directory
[root@localhost redis5]#
[root@localhost redis5]# chkconfig redis5 on
[root@localhost redis5]#
[root@localhost redis5]#
[root@localhost redis5]#
[root@localhost redis5]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
redis5 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost redis5]#
[root@localhost redis5]#
作者:习惯沉淀
如果文中有误或对本文有不同的见解,欢迎在评论区留言。