Ubuntu 18.04 设置开机启动脚本 rc.local systemd
ubuntu18.04不再使用initd管理系统,改用systemd。
ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本,通过下列简单设置后,可以使rc.local重新发挥作用。
1.建立rc-local.service文件
$ sudo vi /etc/systemd/system/rc-local.service
2.复制以下内容
- [Unit]
- Description=/etc/rc.local Compatibility
- ConditionPathExists=/etc/rc.local
- [Service]
- Type=forking
- ExecStart=/etc/rc.local start
- TimeoutSec=
- StandardOutput=tty
- RemainAfterExit=yes
- SysVStartPriority=
- [Install]
- WantedBy=multi-user.target
- ) [Unit] 区块:启动顺序与依赖关系。
- ) [Service] 区块:启动行为,如何启动,启动类型。
- ) [Install] 区块,定义如何安装这个配置文件,即怎样做到开机启动。
有关说明
3. 创建我们自定义的启动脚本(以后自己的脚本在这里面添加即可)
$ sudo vi /etc/rc.local
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
touch /home/xxx/`date +%Y-%m-%d`.log
echo "`df`" > /home/xxx/`date +%Y-%m-%d`.log
echo "看到这行字,说明添加自启动脚本成功。" > /usr/local/test.log
exit 0
- #!/bin/sh -e
- -e 参数可以让脚本执行遇到错误就不往下执行
有关说明
- $ sudo chmod +x /etc/rc.local && sudo systemctl enable rc-local
- Created symlink /etc/systemd/system/multi-user.target.wants/rc-local.service → /etc/systemd/system/rc-local.service.
启动服务,并检查服务(非必要)
- $ sudo systemctl start rc-local.service
- $ sudo systemctl status rc-local.service
- ● rc-local.service - /etc/rc.local Compatibility
- Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset:
- Drop-In: /lib/systemd/system/rc-local.service.d
- └─debian.conf
- Active: active (exited) since Fri 2019-01-25 09:31:07 CST; 9s ago
- Process: 17588 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
- Jan 25 09:31:07 SCHIPS systemd[1]: Starting /etc/rc.local Compatibility...
- Jan 25 09:31:07 SCHIPS systemd[1]: Started /etc/rc.local Compatibility.
参考:
https://www.jianshu.com/p/79d24b4af4e5
https://www.cnblogs.com/defifind/p/9285456.html
Ubuntu 18.04 设置开机启动脚本 rc.local systemd的更多相关文章
- Ubuntu 16.04设置开机启动脚本的方法
需求:公司卡片机容量太小,只有100G,由于使用的人比较的多,开机使用后有时候就会出现磁盘空间占满数据写不进去的情况,影响工作进度,而且每次使用完都得关掉卡片机,所以就有必要写个清理磁盘的脚本,当卡片 ...
- Ubuntu 14.04设置开机启动脚本的方法
rc.local脚本 rc.local脚本是一个ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令.该脚本位于/etc/路径下,需要root权限才能修改. 该脚本具体格式如下: #! ...
- ubuntu-18.04 设置开机启动脚本
ubuntu-18.04 设置开机启动脚本 参阅下列链接 https://askubuntu.com/questions/886620/how-can-i-execute-command-on-sta ...
- ubuntu-18.04 设置开机启动脚本-亲测有效
ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本,通过下列简单设置后,可以使rc.local重新发挥作用. 2.将下列内容复制进rc-local.servi ...
- ubuntu-server-18.04 设置开机启动脚本
ubuntu-16.10 开始不再使用initd管理系统,改用systemd systemd is now used for user sessions. System sessions had al ...
- Ubuntu14.04设置开机启动脚本(转)
原文:https://www.magentonotes.com/ubuntu-config-autostart-shell-script.html 方法一:将脚本添加到文件/etc/rc.local ...
- Ubuntu-18.04设置开机启动脚本
参考:https://www.cnblogs.com/defifind/p/9285456.html http://www.cnblogs.com/airdot/p/9688530.html s ...
- Ubuntu 16.04设置开机启动应用程序
在终端通过以下命令进行设置,Dash已经搜索不到Startup了: gnome-session-properties 或者直接在Dash中搜索:gnome-session
- ubuntu 18.04设置开机自动挂载移动硬盘
首先在命令行执行df -h指令,可以看到如下结果: zifeiy@zifeiy-PC1:~$ df -h 文件系统 容量 已用 可用 已用% 挂载点 udev 964M 0 964M 0% /dev ...
随机推荐
- Django+Xadmin打造在线教育系统(九)
xadmin的进阶开发 因版本问题.有些配置可能无效 自定义icon xadmin的图标采用的是第三方css样式font awesome,我们可以进官网下载最新的样式替代原本的,下载地址:http:/ ...
- CH2906 武士风度的牛(算竞进阶习题)
水..... 直接bfs... #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; typedef l ...
- 【BZOJ2333】【SCOI2011】棘手的操作 treap合并
题目大意 有\(n\)个节点,标号从1到\(n\),这\(n\)个节点一开始相互不连通.第\(i\)个节点的初始权值为\(a_i\),接下来有如下一些操作: \(U~x~y\):加一条边,连接第\(x ...
- windows 系统错误码总结
windows 错误码大全: 操作成功完成. 功能错误. 系统找不到指定的文件. 系统找不到指定的路径. 系统无法打开文件. 拒绝访问. 句柄无效. 存储控制块被损坏. 存储空间不足,无法处理此命令. ...
- Why I don't want use JPA anymore
转自:https://dev.to/alagrede/why-i-dont-want-use-jpa-anymore-fl Great words for what is considered by ...
- 微信小程序框架——wepy使后感
更新:2018年1月10日15:32:22 在ios8及部分机型下会有样式混乱的问题,经查找,原因是缺少浏览器前缀,需要加prefix. 解决方案见链接:wepy-less-autoprefix 另外 ...
- 洛谷P1072 Hankson的趣味题
这是个NOIP原题... 题意: 给定 a b c d 求 gcd(a, x) = b && lcm(c, x) = d 的x的个数. 可以发现一个朴素算法是从b到d枚举,期望得分50 ...
- 洛谷P1173 [NOI2016]网格
这个码量绝对是业界大毒瘤...... 300行,6.5k,烦的要死...... 题意:给你一个网格图,里面有0或1.你需要把一些0换成1使得存在某两个0不四联通.输出最小的换的数量.无解-1. n,m ...
- 洛谷P4070 生成魔咒
题意:给定字符串,求每个前缀的本质不同的子串数量.字符集1e9. 解:在线构造后缀自动机并统计答案. 答案就是∑len[i] - len[fail[i]] 每次增加的时候,至多对三个节点有影响.然而把 ...
- 全面理解虚拟DOM(1)
最近一两年前端最火的技术莫过于 reactjs,angularJS,vuejs,即便你没用过也可能听过,像ReactJS由业界顶尖的互联网公司facebook提出,其本身有很多先进的设计思路,比如页面 ...