AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 29788
Accepted
Geo
Geo
Asked: 2009-06-23 07:07:43 +0800 CST2009-06-23 07:07:43 +0800 CST 2009-06-23 07:07:43 +0800 CST

chkconfig 支持 linux 服务需要什么?

  • 772

我正在尝试通过

chkconfig -add <servicename> 

我收到一条消息说

service <servicename> does not support chkconfig

我正在使用 Red Hat Enterprise 4。我试图在启动时添加到自动启动的脚本如下:

#!/bin/sh

soffice_start() {   if [ -x /opt/openoffice.org2.4/program/soffice ]; then
        echo "Starting Open Office as a Service"
        #echo " soffice -headless -accept=socket,port=8100;urp;StarOffice.ServiceManager
-nofirststartwizard"
        /opt/openoffice.org2.4/program/soffice
-headless -accept="socket,host=0.0.0.0,port=8100;urp;StarOffice.ServiceManager"
-nofirststartwizard &   else
        echo "Error: Could not find the soffice program. Cannot Start SOffice."   fi }

soffice_stop() {   if [ -x /usr/bin/killall ]; then
        echo "Stopping Openoffice"
        /usr/bin/killall soffice 2> /dev/null   else
        echo "Eroor: Could not find killall.  Cannot Stop soffice."   fi }

case "$1" in  'start')    soffice_start    ;;  'stop')    soffice_stop    sleep 2    ;;  'restart')    soffice_stop    sleep 5  soffice_start    ;;  *)    if [ -x /usr/bin/basename ]; then
        echo "usage: '/usr/bin/basename $0' start| stop| restart"    else
        echo "usage: $0 start|stop|restart"    fi esac
linux scripting redhat chkconfig
  • 4 4 个回答
  • 74749 Views

4 个回答

  • Voted
  1. Best Answer
    katriel
    2009-06-23T07:18:29+08:002009-06-23T07:18:29+08:00

    脚本必须有 2 行:

    # chkconfig: <levels> <start> <stop>
    # description: <some description>
    

    例如:

    # chkconfig: 345 99 01
    # description: some startup script
    
    345 - levels to configure
    99 - startup order
    01 - stop order
    

    添加上述标题后,您可以运行chkconfig --add <service>.

    • 78
  2. Kamil Kisiel
    2009-06-23T14:23:10+08:002009-06-23T14:23:10+08:00

    虽然 katriel 已经用创建 init 脚本所需的最低限度来回答这个问题,但我认为您也可以很好地查看/etc/init.d/skeleton并使用它作为您的 init 脚本的模板。你最终会得到一个更加一致和可读的脚本。

    • 6
  3. Topher Hunt
    2015-03-10T07:55:59+08:002015-03-10T07:55:59+08:00

    听起来 Geo 的具体问题已经解决,但我在尝试将 Rails 应用程序设置sidekiq为托管服务时遇到了类似的消息。我将在这里解释我的解决方案,以防它帮助像我这样的其他新手。

    我正在安装 CentOS,chkconfig 已经设置了其他几个服务,如 httpd、mysql 和 redis。请注意,大多数服务只需要在运行级别上3启用5。

    chkconfig --list
    > httpd             0:off   1:off   2:on    3:on    4:on    5:on    6:off
    > mysqld            0:off   1:off   2:on    3:on    4:on    5:on    6:off
    > redis-server      0:off   1:off   2:on    3:on    4:on    5:on    6:off
    > (etc...)
    

    我需要为该sidekiq服务添加一个新脚本,因此我在https://gist.github.com/CD1212/5326706获取了脚本,对其进行了修改以适合我的应用程序的参数,并将其保存在/etc/rc.d/init.d/sidekiq(由 root 拥有,就像所有那里的其他脚本)。

    但是,当我尝试注册此新服务时,出现 chkconfig 错误:

    sudo chkconfig --add sidekiq
    > service sidekiq does not support chkconfig
    

    经过一些额外的阅读后,我发现在每个 chkconfig 脚本顶部定义的优先级编号必须是唯一的。更清晰的错误消息会很好!另一个脚本的关闭优先级为 75,所以我将我的更改为 76 并再次尝试。这是我的初始化脚本的头:

    #!/bin/bash
    #
    # sidekiq    Init script for Sidekiq
    #
    # chkconfig: 345 99 76
    # processname: sidekiq
    # pidfile: /var/www/visual_testing_tool/sidekiq.pid
    # description: Starts and Stops Sidekiq message processor for the Rails app.
    #
    

    这一次,sudo chkconfig --add sidekiq没有抱怨。然后当我运行时sudo chkconfig --list sidekiq,sidekiq 服务显示为on适当的运行级别。

    • 1
  4. George Zamroz
    2016-09-16T18:42:27+08:002016-09-16T18:42:27+08:00

    优先级编号不需要是唯一的。它们仅代表服务的顺序。

    ls -l /etc/rc.d/rc3.d/*oracle lrwxrwxrwx 1 root root 16 Sep 16 12:28 /etc/rc.d/rc3.d/S99oracle -> ../init.d/oracle

    ls -l /etc/rc.d/rc3.d/*it
    lrwxrwxrwx 1 root root 12 Sep 16 12:36 /etc/rc.d/rc3.d/S99it -> ../init.d/it

    Chkconfig 添加“it”服务没有问题。否则,您将被限制为 100 项服务。

    同样在我的示例中,它会在 oracle 之前运行,因为脚本是按字母顺序运行的。

    • 0

相关问题

  • 多操作系统环境的首选电子邮件客户端

  • 你最喜欢的 Linux 发行版是什么?[关闭]

  • 更改 PHP 的默认配置设置?

  • 保护新的 Ubuntu 服务器 [关闭]

  • (软)Ubuntu 7.10 上的 RAID 6,我应该迁移到 8.10 吗?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    Windows 中执行反向 DNS 查找的命令行实用程序是什么?

    • 14 个回答
  • Marko Smith

    如何检查 Windows 机器上的端口是否被阻塞?

    • 4 个回答
  • Marko Smith

    我应该打开哪个端口以允许远程桌面?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    kch 如何更改我的私钥密码? 2009-08-06 21:37:57 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve