[513]linux设置开机自启动
文章目录
- 自启动方法1
- 自启动方法2
- 方法3:在`/etc/rc.d/init.d`目录下添加自启动脚本
- 关机要执行的命令
自启动方法1
1、权限编辑/etc/rc.d/rc.local
cd /etc/rc.d/
vim rc.local
2、在末尾添加执行脚本命令
sh /home/test.sh
3、给脚本赋权限
chmod +x /etc/rc.d/rc.local
chmod +x /home/test.sh
自启动方法2
1、添加启动服务
cd /usr/lib/systemd/systemvim test-autorun.service
将以下内容写到service
[Unit]
Description=emqx for auto start
Wants=network-online.target[Service]
User=root
Type=forking
ExecStart=/usr/bin/bash /home/test.sh start
ExecStop=/usr/bin/bash /root/test.sh stop[Install]
WantedBy=multi-user.target
2、重新加载systemd配置
systemctl daemon-reload
3、添加开机自启动
systemctl enable test-autorun.service
- 重启
$ sudo reboot
- 查看服务状态
$ sudo systemctl status test-autorun.service
方法3:在/etc/rc.d/init.d
目录下添加自启动脚本
linux在/etc/rc.d/init.d
下有很多的文件,每个文件都是可以看到内容的,其实都是一些shell脚本或者可执行二进制文件。
Linux开机的时候,会加载运行/etc/init.d目录下的程序,因此我们可以把想要自动运行的脚本放到这个目录下即可。系统服务的启动就是通过这种方式实现的。
PS:添加完后务必设置文件的可执行权限 chmod +x filename
关机要执行的命令
如果你的系统使用systemd,你可以在/lib/systemd/system-shutdown/
目录中添加一个脚本,systemd-halt.service会处理这个目录中的脚本。
示例(Ubuntu 16.04):
$ sudo vim /lib/systemd/system-shutdown/cleanup.service
[Unit]
Description=Run command at shutdown
# 假设要执行的命令依赖网络
Requires=network.target
DefaultDependencies=no
Before=shutdown.target reboot.target[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=<要执行的命令>(/bin/touch /home/snail/hello)[Install]
WantedBy=multi-user.target
- systemd官方文档:https://www.freedesktop.org/wiki/Software/systemd/
参考:
https://www.cnblogs.com/shih945/p/16561299.html
https://www.cnblogs.com/vofill/p/15752997.html
https://blog.csdn.net/hualinger/article/details/125321966
http://blog.topspeedsnail.com/archives/10203#more-10203
[513]linux设置开机自启动相关推荐
- linux 设置开机自启动 文件配置开机自启动命令
linux 设置开机自启动 文件配置开机自启动命令 在/etc/rc.local文件中添加自启动命令 执行命令 执行脚本 在/etc/init.d目录下添加自启动脚本 运行级别设置 在/etc/rc. ...
- linux 设置开机自启动服务命令,linux开机自启动服务优化设置命令
1.设置成英文字符,避免出现乱码 [root@xuegod62 ~]# LANG=en 2.两种配置linux开机自启动服务命令: 1) [root@xuegod62 ~]# ntsysv 2) [r ...
- linux 设置开机自启动服务命令,linux 设置服务开机自启动
8种机械键盘轴体对比 本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选? 前言 由于机房断电,导致服务关闭,在运维人员匆忙的情况下,可能就只重启了机器,很容易就忽视了里面的服务,而对于比较重要的 ...
- linux设置开机自启动的三种方法
一.rc.local文件中添加自启动命令 1.执行命令: 编辑"/etc/rc.local" vi /ect/rc.local 2.然后在文件最后一行添加要执行程序的全路径. 例如 ...
- linux设置开机自启动(开机启动项)(chkconfig)
/etc/rc.local vim /etc/rc.local 在文件末尾加上你开机需要执行的命令即可(写绝对路径,添加到系统环境变量的除外) Ubuntu开机之后会执行/etc/rc.local文件 ...
- Linux设置开机自启动脚本
这里介绍两种Linux开机自启动脚本的方式 也可用于开机自启动软件(把软件的启动写成脚本,然后再让脚本开机自启动即可) 方式1:/etc/profile.d/ 把自启动脚本放在/etc/profile ...
- linux随机自启命令,linux设置开机自启动
一..在/etc/rc.local文件中添加自启动命令 执行命令: 编辑"/etc/rc.local",添加你想开机运行的命令 运行程序脚本:然后在文件最后一行添加要执行程序的全路 ...
- Linux 设置开机自启动程序
方法一 打开终端,在终端中执行 gnome-session-properties,会弹出一个 "Startup Applications Preferences" 的菜单,点击添加 ...
- Linux 设置开机自启动
/etc/init.d /etc/rc.local 注: /etc/init.d /etc/init.d是/etc/rc.d/init.d的一个目录链接. /etc/rc.d/init.d 存放了各种 ...
最新文章
- Breakpad查C++崩溃问题
- python小学_小学生学python(二)
- 个人随笔之《我有一个需要妈妈帮我实现的愿望》
- 【CV秋季划】深度学习换脸算法视频更新
- deque,list,queue,priority_queue
- C# 消息队列之MSMQ
- jpa 分页 排序 过滤_使用JPA标准@ViewScoped通过分页,过滤和排序进行Primefaces DataTable延迟加载...
- MediaPlayer 的prepareAsync called in state 8 错误
- 情怀也好,相声也好,请拿产品说话!
- (4)Jquery1.8.3快速入门_基本选择器
- Java 对字符以及字符数组的操作
- Windows勒索病毒'Wannacry'修复补丁下载,救命必看!
- 互联网智商测试:搜索引擎谁的“智商”更高?
- 开源XML数据集编辑器
- 零食行业python数据分析实例——基于淘宝搜索排名分析
- 温故而知新(一)—— 再看RNN、LSTM、GRU
- Java动态代理为什么要求必须实现顶级接口
- 微信小程序实现分类列表
- 如何利用fooview实现钉钉自动打卡
- python逻辑量有_python逻辑运算符