系统相关
首页 > 系统相关> > Centos7创建开机自启动服务

Centos7创建开机自启动服务

作者:互联网

方法一:在系统上创建systemctl服务,通过systemctl status | start | restart | disable | enable autoRun.service方式自启服务

1、在/etc/systemd/system下创建autoRun.service文件

2、编辑autoRun.service文件

/etc/systemd/system/autoRun.service

[root@bogon system]# cat auto_run_script.service 

[Unit] 

Description=Run a Custom Script at Startup 

After=default.target 

[Service] 

ExecStart=/opt/project/autoRunScript.sh

 [Install] 

WantedBy=default.target 

[root@bogon system]# 

3、重新加载配置文件

systemctl daemon-reload

systemctl enable autoRun.service

方法二:使用crontab特殊计划任务

crontab -e

@reboot  /opt/project/autoRun.sh

特殊计划任务写法补充

string            meaning 

------           ------- 

@reboot        Run once, at startup. 

@yearly         Run once a year, "0 0 1 1 *". 

@annually      (same as @yearly) 

@monthly       Run once a month, "0 0 1 * *". 

@weekly        Run once a week, "0 0 * * 0". 

@daily           Run once a day, "0 0 * * *". 

@midnight      (same as @daily) 

@hourly         Run once an hour, "0 * * * *".


标签:Run,service,system,Centos7,开机,systemctl,autoRun,自启动,once
来源: https://blog.51cto.com/guoshiwei/2552539