如何在 CentOS 中使用 chkconfig 创建服务?

qro*_*rts 5 linux centos services

我希望能够创建一个服务,以便每次服务器启动时都会运行 bash 脚本。

我正在运行 CentOS 5。

我一直在阅读有关 chkconfig 的信息并在 /etc/init.d 中创建一个文件以供 chkconfig 处理,但是每当我“chkconfig servicename on”然后“service servicename start”时,我似乎都无法让它工作

当我执行 chkconfig --list 时,我的服务列在那里。

有人可以向我提供我需要在 /etc/init.d 中创建的文件示例以及如何让所有内容运行吗?

Pat*_*hes 7

Fedora 项目网站上有一个 initscript 模板

在同一页面的模板下方,是在 RedHat/Fedora/CentOS 系统上为 initscripts 编写头文件的完整说明。如果您需要确保您的脚本在其他服务启动后运行,您只希望脚本在某些情况下运行,或者您希望图形系统管理工具显示有关脚本的完整信息,您可能需要这样做。


Lin*_*000 4

如果您只需要 bash 脚本在每次服务器启动时运行一项或多项操作,则可以从/etc/rc.local运行该脚本。这是我的 - 它通过调用其启动脚本来启动我的媒体服务器应用程序:

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

#NK make sure nas is mounted:
mount -a
/etc/init.d/serviiod start
Run Code Online (Sandbox Code Playgroud)