Linux 添加 init.d 服务(shell 中的 chkconfig / autocomplete)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7615226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:26:57  来源:igfitidea点击:

Adding init.d service (chkconfig / autocomplete in shell)

linuxserviceautocompletezshsystem-administration

提问by Switch

I've made a startup script, (i.e. myserviced) and put it in /etc/init.d/

我制作了一个启动脚本,(即 myserviced)并将其放在 /etc/init.d/

I ran

我跑了

chkconfig --add myserviced

I can start/stop/restart the service just find using:

我可以使用以下命令启动/停止/重新启动该服务:

service myserviced start

etc. However, I notice that when I type "service" and then do TAB (to get a list of possible completions), I don't see myserviced in the list of possible completions (it lists all the other services). How do I add myserviced to the auto-completion list?

等等 但是,我注意到当我键入“service”然后执行 TAB(以获取可能的完成列表)时,我没有在可能的完成列表中看到 myserviced(它列出了所有其他服务)。如何将 myserviced 添加到自动完成列表?

This is in zsh on RHEL.

这是在 RHEL 上的 zsh 中。

Thanks

谢谢

回答by yibe

Make sure myservicedis "executable." (i.e., chmod +x /etc/init.d/myserviced)

确保myserviced是“可执行的”。(即,chmod +x /etc/init.d/myserviced

The completion lists all executablefiles in /etc/init.d, while serviceitself may work regardless of the permission.

完成列出了 中的所有可执行文件/etc/init.d,而service无论权限如何,它本身都可以工作。

回答by Koby

you can use the following command to add all listed scripts in /etc/init.d/to the service command:

您可以使用以下命令将所有列出的脚本添加/etc/init.d/到服务命令中:

complete -W "$(ls /etc/init.d/)" service

-Wwill create word list from the ($)specified path which 'service' will use for auto-complete.

-W将从 ($) 指定的路径创建单词列表,“服务”将用于自动完成。