linux – 如何让这个init.d脚本在服务器重启时启动?
发布时间:2020-12-14 00:53:18 所属栏目:Linux 来源:网络整理
导读:我正在按照在生产机器上安装Redis的说明(使用chkconfig的CentOS). 我给出的示例脚本需要参数start实际启动它,它似乎init.d不执行(传递参数). 必须运行的真正命令是/etc/init.d/redis_6379 start,但实际调用的是/etc/inti.d/redis_6379,它只是说使用start或st
我正在按照在生产机器上安装Redis的说明(使用chkconfig的CentOS).
我给出的示例脚本需要参数start实际启动它,它似乎init.d不执行(传递参数). 必须运行的真正命令是/etc/init.d/redis_6379 start,但实际调用的是/etc/inti.d/redis_6379,它只是说使用start或stop作为参数 因此,当我的服务器重新启动时,它实际上并不启动redis.我该怎么办? 这是初始配置 #!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. # # chkconfig: - 85 15 # description: Redis is a persistent key-value database # processname: redis_6379 REDISPORT=6379 EXEC=/usr/local/bin/redis-server CLIEXEC=/usr/local/bin/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid CONF="/etc/redis/${REDISPORT}.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 ;; *) echo "Please use start or stop as first argument" ;; esac 解决方法
确保通过chkconfig添加脚本以进行服务管理.使用chkconfig –list查看列表并使用chkconfig –add scriptname(如果它不存在).之后配置您希望它被调用的运行级别.我猜它是3,4和5所以:chkconfig –level 345 scriptname on.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |