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 ...
随机推荐
- 调用 setState 之后发生了什么?
(1)代码中调用 setState 函数之后,React 会将传入的参数对象与组件当前的状态合并,然后触发所谓的调和过程(Reconciliation).(2)经过调和过程,React 会以相对高效的 ...
- 让WebService支持Get请求
在C#中,新建一个webservice,默认是post类型的.如果需要支持Get请求,需要对web.config文件进行配置 <system.web> <compilation de ...
- AirServer for Mac(Airplay 终端实用工具)破解版安装
1.软件简介 AirServer 是一款 Mac 上的 AirPlay 终端,通过这款软件,利用 AirPlay 技术,iPhone 或 iPad 就可以无线连接到 Mac 上,不需要在 iPh ...
- [原创]茗洋AaronYang的 jquery.myselect.js 我的一次前端突破[上]
[评论,楼层数为30的倍数的,我送你我自己的博客园的皮肤,该博客参与活动] 介绍 myselect 自己原创的js插件 这是一个可以可以支持ie6+的所有浏览器的,适应很多场景和需求的一个下拉 ...
- 11G新特性 -- archival(long-term)backups
在oracle 10g中,提供了backup ... keep功能来重载配置好的retention策略. 在oracle 11g中,可以重定义backup ... keep命令来创建长期保留的备份,称 ...
- Linux安装R记要
R在Linux上的安装有一些坑(Windows上安装会方便许多),在这里记录,希望可以减少读者不必要的麻烦.我的服务器是SUSE Linux 64位,无法接入互联网(安全原因,你懂的). 到R官网ht ...
- Android studio的主题颜色修改
1.选择喜欢的主题 http://color-themes.com/?view=index 好几十款,总有一款你喜欢 2.下载你喜欢的主题,注意是jar文件 .File -> Import Se ...
- 【emWin】例程十二:FontCvt生成字库
介绍: 本例程介绍使用官方字库生成软件FontCvt5.22生成字库文件,并在液晶上显示文字. 实验指导书及代码包下载: 链接:http://pan.baidu.com/s/1eSkliDW 密码:o ...
- 【30集iCore3_ADP出厂源代码(ARM部分)讲解视频】30-8底层驱动之RTC
视频简介:该视频介绍iCore3应用开发平台中RTC的基本配置方法以及在应用开发平台中的实时显示. 源视频包下载地址:链接:http://pan.baidu.com/s/1o80jHvc 密码:f8r ...
- Spring Security 之Http Basic认证
使用Spring Security进行http Basic认证非常简单,直接配置即可使用,如下: <security:http> <security:http-basic>&l ...