ubuntu18.04不再使用initd管理系统,改用systemd

然而systemd很难用,改变太大,跟之前的完全不同。

使用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()
ConditionFileIsExecutable=/etc/rc.local
After=network.target [Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=
RemainAfterExit=yes
GuessMainPID=no [Install]
WantedBy=multi-user.target
Alias=rc-local.service

1) [Unit] 区块:启动顺序与依赖关系。

2) [Service] 区块:启动行为,如何启动,启动类型。

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

2、创建/etc/rc.local文件

sudo touch /etc/rc.local  

3、赋可执行权限

chmod  /etc/rc.local 

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

#!/bin/bash  

echo "test rc " > /var/test.log  

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

最新文章

  1. Web安全开发之验证码设计不当引发的撞库问题
  2. JQuery实战图片特效-遁地龙卷风
  3. Web Service和ISAPI的区别与联系 转
  4. mybatis_Generator配置
  5. Mac 下纯lua(三)
  6. KVM的虚拟化研究及应用
  7. C#动态表达式计算(续1)
  8. 从c#基础到java基础的学习的感悟
  9. Ant学习笔记
  10. [福大软工教学] W班 第1次成绩排行榜
  11. margin-top塌陷
  12. python之路8-内置模块介绍
  13. 100-days: twenty-seven
  14. curl获取结果乱码的解决方法之CURLOPT_ENCODING(curl/Post请求)
  15. Java-IO基础类回忆
  16. 编译你的第一个Java虚拟机--Centos 7 编译openJdk1.7源码
  17. linux中文件名有英文括号的问题
  18. 对转换公式为LaTeX代码要注意什么
  19. 2018.09.01 loj#2330. 「清华集训 2017」榕树之心(树形dp)
  20. Alwayson--与复制的影响

热门文章

  1. [转]Cross-type joins in Elasticsearch
  2. [LeetCode&Python] Problem 13. Roman to Integer
  3. Unity游戏开发常用的一些函数用法
  4. Unity3D UGUI下拉菜单/Dropdown组件用法、总结
  5. Java中的Arrays类使用详解
  6. flask数据库的迁移
  7. 腾讯云JavaWeb环境配置
  8. 配置url防盗链、目录权限访问控制Directory、文件访问权限控制FilesMatch
  9. rsync命令
  10. Blender Tutorial - Earth curves [Animation nodes]笔记