| 您的当前位置:首页 --> CentOS入门 |
| Centos开机启动脚本 |
| 浏览次数:2185 关键词 ( 脚本 Centos ) |
一)在/etc/init.d下创建启动脚本,并将其设置为可执行文件(chmod +x)
#!/bin/bash
# chkconfig: - 85 15
# description: Gold Web Server.
# Source function library.
. /etc/rc.d/init.d/functions
homedir=/home/jack/goldweb/bin
prog=goldweb
pidfile=/var/run/goldweb.pid
start() {
echo -n $"Starting $prog: "
cd $homedir
./goldweb &
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile}
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile}
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart|status}"
;;
esac
注意:必须有下面两个注释,否则无法用chkconfig添加
# chkconfig: - 85 15 # description: Gold Web Server. 其中chkconfig后跟分别是运行级、启动优先级、关闭优先级 # 缺省的运行级,RHS用到的级别如下: 0:关机 1:单用户模式 2:无网络支持的多用户模式 3:有网络支持的多用户模式 4:保留,未使用 5:有网络支持有X-Window支持的多用户模式 6:重新引导系统,即重启
对各个运行级的详细解释: 0 为停机,机器关闭。 1 为单用户模式,就像Win9x下的安全模式类似。 2 为多用户模式,但是没有NFS支持。 3 为完整的多用户模式,是标准的运行级。 4 一般不用,在一些特殊情况下可以用它来做一些事情。例如在笔记本 电脑的电池用尽时,可以切换到这个模式来做一些设置。 5 就是X11,进到X Window系统了。 6 为重启,运行init 6机器就会重启。 二)用chkconfig添加开机启动
chkconfig --add newservice
chkconfig --list newservice
newservice 0:off 1:off 2:off 3:on 4:on 5:on 6:off
chkconfig --del newservice //删除服务
chkconfig newservice off //关闭开机启动
service newservice status //查询服务状态
service newservice stop //停止服务
service newservice start //启动服务
|
| 下载次数:12 |
| 下载地址:点击下载 |
| 本资源为程序自动采集,如有侵权请联系我们移除 admin#80vps.com 来信请将#替换为@ |
| 下一条 centos系统中网络配置相关 上一条 CentOS下使用Bind配置DNS服务 |