Ubuntu-18.04设置开机启动脚本
参考:https://www.cnblogs.com/defifind/p/9285456.html
http://www.cnblogs.com/airdot/p/9688530.html
systemd 默认读取 /etc/systemd/system 下的配置文件,该目录下的文件会链接/lib/systemd/system/下的文件
打开脚本/lib/systemd/system/rc.local.service 添加末尾几行
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target [Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no [Install]
WantedBy=multi-user.target
elias=rc-local.service
PS:实际测试无需添加最后三行也能实现
最后增加字段[Install]否则在enable的时候可能会报一下错误,虽然报一下错误后开机自启程序还是正常的
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
instance name specified.

创建启动文件/etc/rc.local(默认无该文件)
#!/bin/sh -e
touch /tmp/test
增加执行权限
chmod +x /etc/rc.local
PS:需要#!/bin/sh -e否则可能不生效
设置软连接
ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/
重启如果在/tmp目录下面创建了test文件则代表设置开启启动成功
启动服务并设置开启自启动
systemctl start rc-local
systemctl enable rc-local
重启服务器测试,可以通过命令查看自启动状态以及自启动执行时候的报错等信息
systemctl status rc-local
如果启动rc-local报错
journalctl -xe
单元已失败

检查/etc/rc.local文件配置,是否有非英文状态输入的字符
Ubuntu-18.04设置开机启动脚本的更多相关文章
- Ubuntu 18.04 设置开机启动脚本 rc.local systemd
ubuntu18.04不再使用initd管理系统,改用systemd. ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本,通过下列简单设置后,可以使rc.l ...
- 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 ...
- Ubuntu14.04设置开机启动脚本(转)
原文:https://www.magentonotes.com/ubuntu-config-autostart-shell-script.html 方法一:将脚本添加到文件/etc/rc.local ...
- ubuntu-server-18.04 设置开机启动脚本
ubuntu-16.10 开始不再使用initd管理系统,改用systemd systemd is now used for user sessions. System sessions had al ...
- 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 ...
随机推荐
- shell编程学习笔记(一):编写我的第一段代码
目前在学习Shell编程,我会把我的学习笔记记录在这里.大神可以直接略过~ 嗯,第一段代码,肯定是要输出Hello World了~ 以下蓝色字体的内容为linux命令,红色字体的内容为输出的内容: # ...
- ionic 001
安装和穿件app npm install -g cordova ionic 使用模板创建app ionic start myApp blank ionic start myApp tabs ionic ...
- fork failed because of Out Of Memory
Maybe virtual memory over commit is prevented in your system. If it is prevented, then the virtual m ...
- 【SqlServer】SqlServer的常规操作
创建一张新表,不负责任何数据(该表不会有原来表的主键.索引等等) select * into NewTable from OldTable where 1<>1; 创建一张新表,并且复制旧 ...
- Python 贝叶斯分类
很久的时间没有更新了,一是因为每天加班到比较晚的时间,另外,公司不能上网,回家后就又懒得整理,最近在看机器学习实战的书籍,因此才又决定重新拾起原先的博客! 今天讲的是第三章的贝叶斯分类方法,我们从一个 ...
- Chrome F12 温故而知新 :因为重定向导致清空Network信息
虽然我以前都是用Fiddler 4来作为解决方案.但实际上可以勾选 [Preserve log]来保存日志 这样就不担心因为页面重定向导致清空了日志了
- Git教程学习(三)
主要命令: $ git checkout -- readme.txt #使用暂存区或版本库中最新的版本替换工作区版本 $ git reset HEAD readme.txt # 撤消指定文件的add操 ...
- Django的AbstractUser的几大步骤
- 导入 AbstractUser from django.contrib.auth.models import AbstractUser - 往其中添加列,即可在Django的基础上添加我们所需要的 ...
- 模仿CountDownLatch类自定义倒时计时器
简介 这里模仿CountDownLatch类自定义到时计时器,利用AQS模板中的尝试获得共享和释放共享 1.MyCountDownLatch package com.jacky; import com ...
- Django 源码小剖: Django 中的 WSGI
Django 其内部已经自带了一个方便本地测试的小服务器, 所以在刚开始学习 Django 的时候并不需搭建 apache 或者 nginx 服务器. Django 自带的服务器基于 python w ...