本文是该文的整理版。

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. angular7.X配置同时使用localhost和本机IP访问项目

    1.项目中找到此文件“node_modules/webpack-dev-server/lib/Server.js”,按照下图修改: 二.修改配置文件package.json,见下图: 三.npm st ...

  2. 【python之路40】Python 作用域

    python的作用域与javaScript是一样的,参考:http://www.cnblogs.com/sunshuhai/p/9112578.html 一.python是以函数作为作用域的 if 1 ...

  3. js的几种继承方式

    1.原型链方式 function Super(){ this.val = 1; this.arr = [1]; } function Sub(){ // ... } Sub.prototype = n ...

  4. 傳説中的 jsonp

    jsonp的由來 1 . 網頁上的東西衹要跨域了就不能傳送或者接受數據了.不管是什麽衹要是跨域.Ajax直接请求普通文件存在跨域无权限访问的问题, 2 . 但是src這個東西比較厲害了,請求哪裏都可以 ...

  5. Hdu 1384(差分约束)

    题目链接 Intervals Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  6. IO流4 --- IO流体系 --- 技术搬运工(尚硅谷)

  7. linux文件系统配置文件

    文件系统 内核提供了一个接口,用来显示一些它的数据结构,这些数据结构对于决定诸如使用的中断.初始化的设备和内存统计信息之类的系统参数可能很有用.这个接口是作为一个独立但虚拟的文件系统提供的,称为 /p ...

  8. 在虚拟机Ubuntu14.04中设置静态ip后无法上网的问题的解决

    背景:用着实验室代理服务器上网. 原因:网关和DNS没有设置正确 网关和DNS参照 真机cmd在命令窗口使用ipconfig  /all命令查看   虚拟机: sudo gedit /etc/netw ...

  9. webpack 4.X 创建 react项目

    1. 新建一个文件夹2. 运行 npm init -y 快速初始化项目3. 在跟目录创建src文件夹 dist文件夹4. 在src下创建 index.html main.js // index.htm ...

  10. Spring_Hibernate

    Spring与Hiberante整合 通过hibernate的学习,我们知道,hibernate主要在hibernate.cfg.xml配置文件中 接下来我们看一下hibernate的一个配置文件 h ...