Centos7建立开机自启动服务

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

一、在/etc/systemd/system下建立autoRun.service文件url

二、编辑autoRun.service文件rest

/etc/systemd/system/autoRun.servicecrontab

[root@bogon system]# cat auto_run_script.service ip

[Unit] get

Description=Run a Custom Script at Startup string

After=default.target it

[Service] io

ExecStart=/opt/project/autoRunScript.shclass

 [Install] 

WantedBy=default.target 

[root@bogon system]# 

三、从新加载配置文件

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 * * * *".