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 ...
随机推荐
- Codeforces1036G Sources and Sinks 【构造】【状态压缩】
题目分析: 考虑一个源点集合$S$,如果$S$能到的点$T$比$S$小,那么$T$全连到$S$里面,其它点就到不了$T$啦.否则我们全连完后$S$集合被迫扩大,所以总能扩大满. 代码: #includ ...
- UOJ370 滑稽树上滑稽果 【状压DP】
题目分析: 答案肯定是链,否则可以把枝干放到主干. 去除一直存在的位,这样0位占满时就会结束. 用$f[S]$表示0位填埋情况,每次转移是它的一个子集,我们考虑可否转移. 再用$g[S]$存储转移是否 ...
- 洛谷P1360 [USACO07MAR]黄金阵容均衡题解
题目 不得不说这个题非常毒瘤. 简化题意 这个题的暴力还是非常好想的,完全可以过\(50\%\)的数据.但是\(100\%\)就很难想了. 因为数据很大,所以我们需要用\(O(\sqrt n)\)的时 ...
- 区间DP,数位DP
dp(动态规划)顾名思义便是动态的一种规划,而这种规划往往会跟状态,状态转移方程,记忆化搜索扯上关系,当然DP也是各个OI考试的必考点和常考点,在毒瘤出题人的折磨下,出现了许许多多的动态规划,有线性, ...
- 洛谷P1434滑雪题解及记忆化搜索的基本步骤
题目 滑雪是一道dp及记忆化搜索的经典题目. 所谓记忆化搜索便是在搜索的过程中边记录边搜索的一个算法. 当下次搜到这里时,便直接使用. 而且记忆化搜索一定要满足无后效性,为什么呢,因为如果不满足无后效 ...
- PHP require php > 5.3.0
项目版本要求 在5.3版本以上,如果是用 phpStudy 环境,那么直接切换版本即可
- [luogu4072][bzoj4518][SDOI2016]征途【动态规划+斜率优化】
题目分析 Pine开始了从S地到T地的征途. 从S地到T地的路可以划分成n段,相邻两段路的分界点设有休息站. Pine计划用m天到达T地.除第m天外,每一天晚上Pine都必须在休息站过夜.所以,一段路 ...
- hdu 2149 (巴什博奕)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2149 Problem Description 虽然不想,但是现实总归是现实,Lele始终没有逃过退学的 ...
- js 获取 url 参数
/** * 根据页面地址获取所有参数对象 * @return Object{} 返回所有参数 * ------------------------------ * 根据页面地址获取指定参数对象 * @ ...
- 解决VS2012 服务器资源管理器中的表拖不到Linq to sql中
找到C:\Program Files (x86)\Common Files\microsoft shared\Visual Database Tools\dsref80.dll 这个dll文件: 在其 ...