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

root@debian9 ~ # cat /lib/systemd/system/rc.local.service

#  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

ConditionFileIsExecutable=/etc/rc.local

After=network.target

[Service]

Type=forking

ExecStart=/etc/rc.local start

TimeoutSec=0

RemainAfterExit=yes

GuessMainPID=no

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

root@debian9 ~ # systemctl status rc-local

● rc-local.service - /etc/rc.local Compatibility

Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)

Drop-In: /lib/systemd/system/rc-local.service.d

└─debian.conf

Active: inactive (dead)

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

cat <<EOF >/etc/rc.local

#!/bin/sh -e

#

# rc.local

#

# This script is executed at the end of each multiuser runlevel.

# Make sure that the script will "exit 0" on success or any other

# value on error.

#

# In order to enable or disable this script just change the execution

# bits.

#

# By default this script does nothing.

exit 0

EOF

然后赋予权限

chmod +x /etc/rc.local

接着启动 rc-local 服务

systemctl start rc-local

再次查看状态

root@debian9 ~ # systemctl status rc-local

● rc-local.service - /etc/rc.local Compatibility

Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)

Drop-In: /lib/systemd/system/rc-local.service.d

└─debian.conf

Active: active (exited) since Thu 2017-08-03 09:41:18 UTC; 14s ago

Process: 20901 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

Aug 03 09:41:18 xtom-proxy systemd[1]: Starting /etc/rc.local Compatibility...

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. Android--MP3播放器MediaPlayer

    前言 Android提供了常见的音频.视频的编码.解码机制.借助于多媒体类MediaPlayer的支持,开发人员可以很方便在在应用中播放音频.视频.本篇博客主要讲解在Android平台下如何播放一个音 ...

  2. Vim编辑器显示行数

    很多时候,我们编写代码的时候,编译器报错,在某一行,这时我们虽然可以:行数来跳转,但是没有直观的行数,总是感觉不妥,vi和vim默认是没有行号的,那么怎么办呢?下面我就教你怎么设置行号. 工具: 一台 ...

  3. 补习系列(7)-springboot 实现拦截的五种姿势

    目录 简介 姿势一.使用 Filter 接口 1. 注册 FilterRegistrationBean 2. @WebFilter 注解 姿势二.HanlderInterceptor 姿势三.@Exc ...

  4. 聊聊 scala 的模式匹配

    一. scala 模式匹配(pattern matching) pattern matching 可以说是 scala 中十分强大的一个语言特性,当然这不是 scala 独有的,但这不妨碍它成为 sc ...

  5. Spring Boot(十四)RabbitMQ延迟队列

    一.前言 延迟队列的使用场景:1.未按时支付的订单,30分钟过期之后取消订单:2.给活跃度比较低的用户间隔N天之后推送消息,提高活跃度:3.过1分钟给新注册会员的用户,发送注册邮件等. 实现延迟队列的 ...

  6. 痞子衡嵌入式:飞思卡尔Kinetis开发板OpenSDA调试器那些事(上)- 背景与架构

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是飞思卡尔Kinetis MCU开发板板载OpenSDA调试器(上篇). 众所周知,嵌入式软件开发几乎离不开调试器,因为写一个稍有代码规模 ...

  7. python中循环删除列表中元素时的坑!

    循环删除列表中元素时千万别用正序遍历,一定要用反序遍历! 废话不多说,先上案例代码: def test(data): for i in data: data.remove(i) return data ...

  8. 消息队列中间件(三)Kafka 入门指南

    Kafka 来源 Kafka的前身是由LinkedIn开源的一款产品,2011年初开始开源,加入了 Apache 基金会,2012年从 Apache Incubator 毕业变成了 Apache 顶级 ...

  9. 第17章 社区快速入门和模板 - Identity Server 4 中文文档(v1.0.0)

    IdentityServer组织不维护这些示例.IdentityServer组织愉快地链接到社区模板,但不能对模板做出任何保证.请直接与作者联系. 17.1 各种ASP.NET核心安全样本 https ...

  10. UED视觉交互设计与流程介绍

    UED视觉交互设计与流程介绍 ------------------------------------------------------------------ 今天先到这儿,希望对您技术领导力, ...