本文是该文的整理版。

Ubuntu18.04不再使用initd管理系统,改用systemd。为了像以前一样,在/etc/rc.local中设置开机启动程序,需要以下几步:

1、systemd默认读取/etc/systemd/system下的配置文件,该目录下的文件会链接/lib/systemd/system/下的文件。一般系统安装完/lib/systemd/system/下会有rc-local.service文件,即我们需要的配置文件。

创建软链接:

ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service 
cd /etc/systemd/system/
cat rc-local.service

rc-local.service内容

#  SPDX-License-Identifier: LGPL-2.1+
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version. # This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[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
Alias=rc-local.service   

区块解释:

  [Unit]:启动顺序与依赖关系。

  [Service]:启动行为,如何启动,启动类型。

  [Install] :定义如何安装这个配置文件,即怎样做到开机启动。

2、创建/etc/rc.local文件,赋可执行权限

touch /etc/rc.local
chmod 755 /etc/rc.local

  

3、编辑/etc/rc.local,添加需要开机启动的任务

#!/bin/bash
echo "test rc " > /var/test.log

  

4、执行reboot重启系统,然后查看test.log

sudo reboot

  

Ubuntu18.04 systemd开机自启的更多相关文章

  1. ubuntu18.04设置开机自启Django

    设置开机自启: rc-local.server [Unit] Description=/etc/rc.local Compatibility ConditionPathExists=/etc/rc.l ...

  2. ubuntu-18.04 设置开机启动脚本

    ubuntu-18.04 设置开机启动脚本 参阅下列链接 https://askubuntu.com/questions/886620/how-can-i-execute-command-on-sta ...

  3. ubuntu-18.04 设置开机启动脚本-亲测有效

    ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本,通过下列简单设置后,可以使rc.local重新发挥作用. 2.将下列内容复制进rc-local.servi ...

  4. ubuntu16.04设置开机自启服务

    网上说了开机自启有许多种方法: 1.最简单的是:在/etc/rc.local的exit 0前面加上你启动服务的脚本文件路径 注:这个脚本文件应写绝对路径! 2.网上:修改rc.local开头的#/bi ...

  5. Ubuntu-18.04设置开机启动脚本

    参考:https://www.cnblogs.com/defifind/p/9285456.html    http://www.cnblogs.com/airdot/p/9688530.html s ...

  6. Ubuntu18.04 设置开机进入命令行模式

    首先来了解下启动级别(Runlevel): 指 Unix 或 类 Unix 操作系统下不同的运行模式,运行级别通常分为 7 级: 运行级别 0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启 ...

  7. Linux 7开机自启项查看并设置

      在Linux6中查看及设置开机自启信息是使用chkconfig命令,Linux7中此命令已经被替代,接下来我们就来研究下Linux7中的区别所在. chkconfig --list Note: T ...

  8. Ubuntu 18.04 设置开机启动脚本 rc.local systemd

    ubuntu18.04不再使用initd管理系统,改用systemd. ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本,通过下列简单设置后,可以使rc.l ...

  9. 树莓派 ubuntu16.04 安装SSH 配置SSH 开机自启SSH

    入手个树莓派3B 装了 ubuntu 16.04 需要用到SSH 记录下 0.先获得树莓派IP 树莓派 使用网线连接路由器和树莓派 在路由器设置页面(一般是192.168.1.1具体看路由器的型号和设 ...

随机推荐

  1. TZ_14_Zuul网关

    1.spring-cloud的微服务大致是 2.zuul是 Netflix开源的微服务网关, 它可以和 Eureka. Ribbon. Hystrix等组件配合使用.zul的核心是一系列的过滤器,这些 ...

  2. Linq 之 Where操作

    适用场景:实现过滤,查询等功能. 说明:与SQL命令中的Where作用相似,都是起到范围限定也就是过滤作用的,而判断条件就是它后面所接的子句. Where操作包括3种形式,分别为简单形式.关系条件形式 ...

  3. tomcat的访问日志

    https://blog.csdn.net/qq_30121245/article/details/52861935 配置位置在这里,每一个域名设置都可以单独设置 %a   这是记录访问者的IP,如果 ...

  4. mysql 无法存储joda time的datetime类型

    com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '\xAC\xED\x00\x05sr\x ...

  5. iostat统计信息

    用途:报告中央处理器(CPU)统计信息和整个系统.适配器.tty 设备.磁盘和 CD-ROM 的输入/输出统计信息. 语法:iostat [ -c | -d ] [ -k ] [ -t | -m ] ...

  6. node的源码安装

    Node.js 安装配置 本章节我们将向大家介绍在 Windows 和 Linux 上安装 Node.js 的方法. 本安装教程以 Node.js v4.4.3 LTS(长期支持版本)版本为例. No ...

  7. BZOJ1455罗马游戏

    左偏树裸题. 题面描述让人意识到了平面几何的重要性. //Achen #include<algorithm> #include<iostream> #include<cs ...

  8. 理解async和await

    async 是“异步”的简写,而 await 可以认为是 async wait 的简写. 所以应该很好理解 async 用于申明一个 function 是异步的,而 await 用于等待一个异步方法执 ...

  9. 注解1 --- JDK内置的三个基本注解 --- 技术搬运工(尚硅谷)

    @Override: 限定重写父类方法, 该注解只能用于方法 @Deprecated: 用于表示所修饰的元素(类, 方法等)已过时.通常是因为所修饰的结构危险或存在更好的选择 @SuppressWar ...

  10. SDUT-3402_数据结构实验之排序五:归并求逆序数

    数据结构实验之排序五:归并求逆序数 Time Limit: 50 ms Memory Limit: 65536 KiB Problem Description 对于数列a1,a2,a3-中的任意两个数 ...