由于某些软件并没有增加开启启动的服务,很多时候需要手工添加,一般我们都是推荐添加命令到 /etc/rc.local 文件,但是 Debian 9 默认不带 /etc/rc.local 文件,而 rc.local 服务却还是自带的

  1. root@debian9 ~ # cat /lib/systemd/system/rc.local.service
  2.  
  3. # This file is part of systemd.
  4.  
  5. #
  6.  
  7. # systemd is free software; you can redistribute it and/or modify it
  8.  
  9. # under the terms of the GNU Lesser General Public License as published by
  10.  
  11. # the Free Software Foundation; either version 2.1 of the License, or
  12.  
  13. # (at your option) any later version.
  14.  
  15. # This unit gets pulled automatically into multi-user.target by
  16.  
  17. # systemd-rc-local-generator if /etc/rc.local is executable.
  18.  
  19. [Unit]
  20.  
  21. Description=/etc/rc.local Compatibility
  22.  
  23. ConditionFileIsExecutable=/etc/rc.local
  24.  
  25. After=network.target
  26.  
  27. [Service]
  28.  
  29. Type=forking
  30.  
  31. ExecStart=/etc/rc.local start
  32.  
  33. TimeoutSec=0
  34.  
  35. RemainAfterExit=yes
  36.  
  37. GuessMainPID=no

并且默认情况下这个服务还是关闭的状态

  1. root@debian9 ~ # systemctl status rc-local
  2.  
  3. rc-local.service - /etc/rc.local Compatibility
  4.  
  5. Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
  6.  
  7. Drop-In: /lib/systemd/system/rc-local.service.d
  8.  
  9. └─debian.conf
  10.  
  11. Active: inactive (dead)

为了解决这个问题,我们需要手工添加一个 /etc/rc.local 文件

  1. cat <<EOF >/etc/rc.local
  2.  
  3. #!/bin/sh -e
  4.  
  5. #
  6.  
  7. # rc.local
  8.  
  9. #
  10.  
  11. # This script is executed at the end of each multiuser runlevel.
  12.  
  13. # Make sure that the script will "exit 0" on success or any other
  14.  
  15. # value on error.
  16.  
  17. #
  18.  
  19. # In order to enable or disable this script just change the execution
  20.  
  21. # bits.
  22.  
  23. #
  24.  
  25. # By default this script does nothing.
  26.  
  27. exit 0
  28.  
  29. EOF

然后赋予权限

  1. chmod +x /etc/rc.local

接着启动 rc-local 服务

  1. systemctl start rc-local

再次查看状态

  1. root@debian9 ~ # systemctl status rc-local
  2.  
  3. rc-local.service - /etc/rc.local Compatibility
  4.  
  5. Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
  6.  
  7. Drop-In: /lib/systemd/system/rc-local.service.d
  8.  
  9. └─debian.conf
  10.  
  11. Active: active (exited) since Thu 2017-08-03 09:41:18 UTC; 14s ago
  12.  
  13. Process: 20901 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
  14.  
  15. Aug 03 09:41:18 xtom-proxy systemd[1]: Starting /etc/rc.local Compatibility...
  16.  
  17. Aug 03 09:41:18 xtom-proxy systemd[1]: Started /etc/rc.local Compatibility.

然后你就可以把需要开机启动的命令添加到 /etc/rc.local 文件,丢在 exit 0 前面即可,并尝试重启以后试试是否生效了

转载自https://www.zhangweijie.net/post/2017/08/14/2868.html

----------------------------------- 后  记---------------------------------------------

当初我是为了将ankiserver部署到debian9 虚拟机上,并让它随着虚拟机启动而启动ankiserver服务而查的资料。

另外案例下另外一个收获:让你的vmware 随机启动,并让虚拟机也启动,关机时停止运行

https://www.cnblogs.com/chenxiaonian/p/6274965.html   注意,将vmware的目录设为环境变量

https://www.vmware.com/support/ws5/doc/ws_learning_cli_vmrun.html

搭建anki server时,我参考的https://zhuanlan.zhihu.com/p/25042942?refer=-anki  和 https://www.jianshu.com/p/c50e3feec878

debian 9 开机启动的更多相关文章

  1. debian开机启动管理

    debian开机启动管理(转文) linux下,services的启动.停止等通常是通过/etc/init.d的目录下的脚本来控制的.在启动或改变运行级别是在/etc/rcX.d中来搜索脚本.其中X是 ...

  2. Debian - 设置MYSQL开机启动

    设置MYSQL 首先拷贝mysql.server到/etc/init.d目录下命名为mysql # cp /自己的安装目录/mysql/share/mysql/mysql.server /etc/in ...

  3. Debian 9.x "stretch" 解决 /etc/rc.local 开机启动问题

    由于某些软件并没有增加开启启动的服务,很多时候需要手工添加,一般我们都是推荐添加命令到 /etc/rc.local 文件,但是 Debian 9 默认不带 /etc/rc.local 文件,而 rc. ...

  4. Debian/Ubuntu/CentOS开机启动

    说明:常用的Linux启动项就是在/etc/rc.local的exit 0语句之间添加启动脚本,另一种方法,使用update-rc.d命令添加/禁止开机启动项. 在centos7中增加脚本有两种常用的 ...

  5. ubuntu下设置开机启动服务

    原文:http://blog.csdn.net/dante_k7/article/details/7213151 在ubuntu10.04之前的版本都是使用chkconfig来进行管理,而在之后的版本 ...

  6. linux 开机启动过程详解

    Linux开机执行内核后会启动init进程,该进程根据runlevel(如x)执行/etc/rcx.d/下的程序,其下的程序是符号链接,真正的程序放在/etc/init.d/下.开机启动的程序(服务等 ...

  7. linux 开机启动设置

    操作系统:Ubuntu12.04硬件环境:HP CQ45        当用户使用sudo apt-get install安装完apache和mysql之后,这些服务默认是开机启动的,但是有的时候需要 ...

  8. 原 Debian设置开机自动启动与关闭

    发表于1年前(2013-01-08 13:01)   阅读(2380) | 评论(0) 2人收藏此文章, 我要收藏 赞0 开机自动启动 update-rc.d chkconfig 熟悉debian系统 ...

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

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

随机推荐

  1. Python必备库

    Python必备库 --default-timeout=100避免网络延迟错误:-U给管理员权限. Python基础库 pip --default-timeout=100 install -U pyg ...

  2. Python内置函数(4)——ascii

    英文文档: ascii(object) As repr(), return a string containing a printable representation of an object, b ...

  3. 10.Flask上下文

    1.1.local线程隔离对象 不用local对象的情况 from threading import Thread request = ' class MyThread(Thread): def ru ...

  4. C++、Java语法差异对照表

    C++.Java语法差异对照表 C++ and Java Syntax Differences Cheat Sheet First, two big things--the main function ...

  5. WebSocket刨根问底(二)

    上篇文章[WebSocket刨根问底(一)]中我们对WebSocket的一些基本理论进行了介绍,但是并没有过多的涉及到一些实战的内容,今天我希望能够用几个简单的案例来向小伙伴们展示下WebSocket ...

  6. 如何判断DataSet里有多少个DataTable

    dataset.table.count sda.fill(ds,"table"); //这里是在ds里新建了一个表,叫table,注意是新建,多次执行会报错,实际使用时,可以用co ...

  7. .Net高并发解决思路(附源码)

    本文如有不对之处,欢迎各位拍砖扶正.另源码在文章最下面,大家下载过后先还原一下nuget包,需要改一下redis的配置,rabbitmq的配置以及Ef的连接字符串.另外使用的是CodeFirst,先u ...

  8. spring框架应用系列四:切面编程(环绕通知与前后置通知区别)

    切面编程(环绕通知与前后置通知区别) 本文系作者原创,转载请注明出处:http://www.cnblogs.com/further-further-further/p/7867034.html 解决问 ...

  9. 痞子衡嵌入式:通用NOR接口标准(CFI-JESD68)及SLC Parallel NOR简介

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是CFI标准及SLC Parallel NOR. NOR Flash是嵌入式世界里最常见的存储器,常常内嵌在微控制器里(Parallel型 ...

  10. Atom编辑器插件

    一.atom由于安装的插件过多导致tab键失效解决办法如下: 打开File→Keymap中keymap.cson文件,将以下代码复制到文件: 'atom-text-editor:not([mini]) ...