centos 重启自动运行脚本

在一个 shell 脚本中执行另一个 shell 脚本的3种方法

1
2
3
./bar.sh fork
./bar.sh exec
./bar.sh source

编辑启动脚本 /etc/init.d/autorun.sh

脚本前三行如下:

1
2
3
#!/bin/sh
#chkconfig: 2345 80 90
#description:auto_run

参考:http://blog.chinaunix.net/uid-20521628-id-365862.html

开启自启动服务

1
2
chkconfig --add autorun.sh
chkconfig autorun.sh on

关闭自启动服务

1
chkconfig autorun.sh off

查看自启动服务

1
chkconfig --list

autorun.sh 重启一些服务

1
2
3
4
5
6
7
8
9
#!/bin/sh
#chkconfig: 2345 80 90
#description:auto_run
# 启动 nginx
nginx
# 启动 jenkins
systemctl start jenkins
# 执行 shell 脚本
/path/to/mongod_start.sh fork