Linux中软件自启动三种方式
一、介绍Linux环境中软件自启动的三种方式,测试环境为Centos7。三种方式为:1、systemd服务2、使用 /etc/rc.d/rc.local3、使用crontab定时计划中的@reboot二、详细操作1、systemd方式2、rc.local方式3、crontab定时计划中的@reboo.........
·
一、介绍
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
删除定时任务
更多推荐
已为社区贡献1条内容
所有评论(0)