chkconfig 未添加 redis 初始化脚本

chkconfig not adding redis init script

我正在尝试将 redis 添加到我的 CentOS 虚拟机的启动中,但 chkconfig 似乎没有添加它。 我对其他几个初始化脚本执行了相同的过程,并且它们添加得很好。任何帮助告诉我我做错了什么都会很棒。 我查看了手册页并搜索了 google,但每件事都说要添加我已有的 header 值。我为 hornetq init 脚本和 smpp 模拟器脚本编写了相同的 case 语句,并简单地更改了 do_start 和 do_stop 函数的内容以完成它们各自的工作。

我是运行添加init脚本的如下命令:

chkconfig --add /etc/init.d/redis

然后我检查列表:

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]'.

hornetq         0:off   1:off   2:off   3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
smppsim         0:off   1:off   2:off   3:on    4:on    5:on    6:off

我写的脚本是这样的:

#!/bin/sh
#
# startup script for running redis as a service.
#
# chkconfig: 350 95 15
# description: redis startup script
do_start(){
  systemctl start redis.service
}
do_stop(){
  systemctl stop redis.service
}
do_status(){
  systemctl status redis.service
}
case "" in
'start')
    do_start
    do_status
    ;;
'stop')
    do_stop
    do_status
    ;;
'status')
    do_status
    ;;
'restart')
    do_stop
    do_start
    ;;
*)
    echo "usage: [=14=] start|stop|status|restart"
esac

*****编辑******

仅供参考 运行 "service redis start" 工作正常

命令是 chkconfig --add [name] 而不是 chkconfig --add [path] 所以你想要 chkconfig --add redis.

话虽如此,在 systemd 系统上您甚至不必费心使用 init.d 服务脚本,因为您不需要它。

"legacy" service 命令已更新以正常处理启动 systemd 服务,因此您 possibly/probably 甚至没有使用您的脚本(如果您正在使用,因为您的脚本只是转发到systemctl 你不需要它,因为正如我所说,service 命令已经为你完成了。

要模拟 chkconfig 启动服务的功能,您要使用 systemctl enable <service>