centos7下自定义服务启动和自动执行脚本

systemctl list-units --type=service #查看所有已启动的服务

 systemctl enable httpd.service   #加入开机自启动服务

 systemctl enable rsyncd.service   #同步数据的服务

2、开机后执行自定义脚本

1)编辑自启动脚本的文件

vim /yourpath/serverstart_all.sh

#!/bin/bash
sh /yourserverpath/server_start.sh

2)将脚本标记为可执行文件

chmod +x /yourpath/serverstart_all.sh

3)将/etc/rc.d/rc.local文标记为可执行文件

chmod +x /etc/rc.d/rc.local

4)编辑/etc/rc.d/rc.local文件,增加 自启动脚本的执行

vim /etc/rc.d/rc.local
/yourpath/serverstart_all.sh

 这里做了个启动后的测试,在serverpath的log下输出结果文件,重启后输出正常

filename="/yourserverpath/log/`date +%y%m%d_%H%M%S_`"
sh /yourserverpath/server_start.sh>$filename"servername.log"

 3、开机后制动检测并启动特定进程 

ps aux|grep yourprocessname

原文地址:https://www.cnblogs.com/mousean/p/6038026.html