linux - chkconfig 不添加 redis 初始化脚本

标签 linux centos initialization startup

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

我正在运行以下命令来添加初始化脚本:

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 "$1" in
'start')
    do_start
    do_status
    ;;
'stop')
    do_stop
    do_status
    ;;
'status')
    do_status
    ;;
'restart')
    do_stop
    do_start
    ;;
*)
    echo "usage: $0 start|stop|status|restart"
esac

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

仅供引用,运行“service redis start”就可以了

最佳答案

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

在 systemd 系统上,你甚至不应该为 init.d 服务脚本烦恼,因为你不需要它。

“遗留”service 命令已更新以正常处理启动 systemd 服务,因此您可能/可能甚至没有使用您的脚本(如果您是因为您的脚本只是转发到 systemctl,您不需要它,因为我说过,service 命令已经为您完成了)。

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

关于linux - chkconfig 不添加 redis 初始化脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31094002/

相关文章:

java - CentOS 6 中 JVM 的 CPU 使用率总是超过 100%

linux - CentOS 上使用 DNS 的所有网络事件延迟

ruby - 数组初始化和方法计数增加 ?秘诀是什么?

linux - tar zxf 与 -xvf 之间的区别

c++ - 将堆栈对象等同于对象 C++ 中的另一个对象

java - 使用类中的方法初始化实例变量

linux - 带有 "scp"的 Elixir——权限被拒绝并且连接丢失

linux - Linux下的特殊文件?

linux - CUDA - 关于 “branch” 和 “divergent branch” 的 Visual Profiler 结果的混淆 (2)

linux - Oracle virtual box 登录账号/用户不存在