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 ...
随机推荐
- 洛谷P3183食物链题解
不得不说,这是道很难减少时间复杂度的题,且这个题有点像一道拓扑排序题,但是这个难度标签有点低. 我们应该可以想到拓扑排序可能是这个题的正解,但是题目中有输出总数,因此我们就可以造一个数组表示从这个点出 ...
- Pleasant sheep and big big wolf HDU - 3046(最小割)
Pleasant sheep and big big wolf Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- 【BZOJ3999】【TJOI2015】旅游 树剖
题目大意 给你一棵树,有\(n\)个点.有\(q\)个操作,每次要你从\(x\)到\(y\)的路径上选两个点,使得距离\(x\)比较远的点的点权\(-\)距离\(x\)比较近的点的点权最大,然后把这条 ...
- MT【264】分式变形
已知$x,y>0,\dfrac{1}{x}+\dfrac{2}{y}=1$,求$\dfrac{1}{x+1}+\dfrac{2}{y+1}$的最大值____ 解答:令$a=\dfrac{1}{x ...
- 「HDU6158」 The Designer(圆的反演)
题目链接多校8-1009 HDU - 6158 The Designer 题意 T(<=1200)组,如图在半径R1.R2相内切的圆的差集位置依次绘制1,2,3,到n号圆,求面积之和(n< ...
- awk文本分析工具
Usage:awk [option] 'program' file ... awk [option] -f progfile file ... [optin]: -F fs 指定输入分隔符,fs可是字 ...
- 【CF809D】Hitchhiking in the Baltic States(Splay,动态规划)
[CF809D]Hitchhiking in the Baltic States(Splay,动态规划) 题面 CF 洛谷 题解 朴素\(dp\):设\(f[i][j]\)表示当前考虑到第\(i\)个 ...
- 「TJOI2015」组合数学 解题报告
「TJOI2015」组合数学 这不是个贪心吗? 怎么都最小链覆盖=最大点独立集去了 注意到一个点出度最多只有2,可以贪心一下出度的去向 按读入顺序处理就可以,维护一个\(res_i\)数组,表示上一行 ...
- bzoj4383(拓扑排序)
给定一个长度为n的正整数序列a,每个数都在1到10^9范围内,告诉你其中s个数,并给出m条信息,每条信息包含三个数l,r,k以及接下来k个正整数,表示a[l],a[l+1],...,a[r-1],a[ ...
- 合法括号序列(dp+组合数学)
键盘上有左括号(,右括号),和退格键-,共三个键. 牛牛希望按键n次,使得输入的字符串恰好一个合法的括号序列. 每按一次左括号(,字符串末尾追加一个左括号( 每按一次右括号),字符串末尾追加一个右括号 ...