创建Redhat/CentOS Service的一般方法

1. 在/etc/init.d下创建Service启动脚本

例如:vi /etc/init.d/some_service

脚本头部的固定写法:

#!/bin/sh

#chkconfig: 2345 85 15

#description: some desc here

#processname: the_process_name

其中2345是runlevel,即2-5,85是系统启动顺序,15是系统关闭顺序

当然,它要有运行权限: chmod +x /etc/init.d/some_service

2. 注册到系统

chkconfig --add some_service

3. 设置随系统启动

激活:

chkconfig some_service on

取消:

chkconfig some_service off