centOS 开机自启动自己的脚本

centOS 开机自启动自己的脚本

1. 自己脚本 myservice 如下:

#!/bin/bash
# chkconfig: 2345 10 90
# description: myservice ....

echo "hello world" > /tmp/hello.log

2. 将自己写的脚本move到 /etc/rc.d/init.d/ 下面并修改权限

mv myservice /etc/rc.d/init.d/
chmod +x myservice

3. 将脚本加入开机服务

chkconfig --add myservice             #把myservice添加到系统服务列表
chkconfig myservice on                 #设定myservice的开关(on/off)
chkconfig --list myservice               #就可以看到已经注册了myservice的服务 

备注:

  自己写的脚本myservice 中如果# chkconfig: 2345 10 90  # description: myservice .... 这两行没有写会报错  “service myservice does not support chkconfig

因为chkconfig 会读这两行并配置服务的优先级;

 
原文地址:https://www.cnblogs.com/aaron-agu/p/7610629.html