Linux中软件自启动三种方式

一、介绍

        Linux环境中软件自启动的三种方式,测试环境为Centos7。三种方式为:

1、systemd服务

2、使用 /etc/rc.d/rc.local

3、使用crontab定时计划中的@reboot

二、详细操作

1、systemd方式

(1)文件编辑(systemd)

1、进入目录
cd /etc/systemd/system/

2、创建,输入执行内容
vi test.service    //输入
[Unit]
Description=record system reboot time

[Service]
ExecStart=/home/test.sh    #执行脚本,脚本为可执行(chmod a+x)
Restart=on-failure         #非正常退出重启
RestartSec=3s              #重启时间
StandardOutput=null        #输出的日志不会写入系统日志文件(写入系统日志文件会让系统日志文件非常大)

[Install]
WantedBy=default.target    

3、设置服务
systemctl daemon-reload
systemctl enable test.service

4、取消方法
systemctl disable test.service

 

 

(2)命令行(systemctl)

1、设置开机启动
systemctl enable test.sh

2、取消开机启动
systemctl disenable test.sh

3、查询信息状态
systemctl status test.sh

4、查询是否开机启动
systemctl is-enable test.sh

5、查询当前是否启动
systemctl is-active test.sh

6、立即启动
systemctl start test.sh

7、立即停止
systemctl stop test.sh

8、重启
systemctl restart test.sh

2、rc.local方式

1、打开rc.local
vi /etc/rc.d/rc.local

2、添加执行内容
/home/test.sh

3、修改rc.local权限
chmod +x /etc/rc.d/rc.local

4、取消方式
打开/etc/rc.d/rc.local文件,删除执行内容

3、crontab定时计划中的@reboo

1、打开定时脚本
crontab -e

2、添加定时任务
@reboot /home/test.sh

3、取消方法
crontab -e
删除定时任务

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值