由于某些软件并没有增加开启启动的服务,很多时候需要手工添加,一般我们都是推荐添加命令到 /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-hk systemd[1]: Starting /etc/rc.local Compatibility... Aug 03 09:41:18 xtom-hk systemd[1]: Started /etc/rc.local Compatibility.

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

debian9 开启rc.local服务的更多相关文章

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

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

  2. centos7 /etc/rc.local需要chmod +x /etc/rc.d/rc.local

    Centos 7.0设置/etc/rc.local无效问题解决 安装centos7以后按照以往习惯修改rc.local添加开机启动命令,但重启后发现无效,再次重启发现依然如故 检查系统rc.local ...

  3. Centos 7.0设置/etc/rc.local无效问题解决

    安装centos7以后按照以往习惯修改rc.local添加开机启动命令,但重启后发现无效,再次重启发现依然如故 检查系统rc.local服务运行情况 systemctl | grep "rc ...

  4. /etc/rc.d/rc.local linux启动自动开启某些服务(转)

    /etc/rc.d/rc.local似乎是很多Linux系统管理员的偏爱,因为凡是需要随系统自动启动的服务.程序等,只要系统没有提供Sys V风格的启动脚本,就把这些需求都塞到/etc/rc.d/rc ...

  5. 通过/etc/rc.local实现开机自动拉起服务

    添加服务到/etc/rc.local 如自动拉起apache服务: /etc/rc.local: #!/bin/sh # # This script will be executed *after* ...

  6. rc.local 开启自启动,检测是否成功

    rc.local /etc/init.d/nginx start 查看运行状态 systemctl status rc-local ● rc-local.service - /etc/rc.local ...

  7. rc-local.service服务启动失败,导致rc.local中的开机启动服务不能启动

    chmod  +x   /etc/rc.d/rc.local 打开/etc/rc.local文件,将启动非后台执行的指令的最后添加 &,以使相关指令后台运行,然后启动服务 systemctl  ...

  8. Ubuntu 16.04设置rc.local开机启动命令/脚本的方法(通过update-rc.d管理Ubuntu开机启动程序/服务)

    注意:rc.local脚本里面启动的用户默认为root权限. 一.rc.local脚本 rc.local脚本是一个Ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令.该脚本位于/et ...

  9. rc.local添加tomcat服务启动命令,但是tomcat服务无法正常启动

    遇到了一个特别坑的问题. 本来想着在rc.local文件里添加tomcat启动命令,使tomcat开机自启.之前在其他服务器上直接这样操作是没问题的,但很幸运的是,现在忽然就不行了. 开始排错: 1. ...

随机推荐

  1. JVM·垃圾收集器与内存分配策略之垃圾收集器!

    1.Serial(串行)收集器(新生代都采用复制算法)     这是个单线程的收集器:即 当他工作的时候,会停掉虚拟机所有的线程!(Stop The World)

  2. js基础学习

  3. Android:四大架构的优缺点,你真的了解吗?

    声明|转载于作者:KunMinX原文链接:https://www.jianshu.com/p/9ef813d5c1af 前言 前不久刚结束对 20 模块项目的第 3 轮重构,一路见证 MVC.MVP. ...

  4. Python yield使用浅析

    yield可将一个函数变成生成器,每次调用时,返回yield的结果,下次迭代时,从yield 下条语句开始执行. 一个典型的例子,斐波拉切数列: def fab(max): n, a, b = 0, ...

  5. jquery 中多选和全选

  6. 使用 Kafka 和 Spark Streaming 构建实时数据处理系统

    使用 Kafka 和 Spark Streaming 构建实时数据处理系统 来源:https://www.ibm.com/developerworks,这篇文章转载自微信里文章,正好解决了我项目中的技 ...

  7. 【linux】复制文件夹中文件,排除部分文件

    如下 cp `ls|grep -v -E '*json|out'|xargs` /home/data/ 用grep -v  表示排除, -E 表示正则 ls|grep -v -E '*json|out ...

  8. 【python】gevent协程例子

    说在前面:用协程还是多线程需要仔细考量.我在做实验时请求了100w个ip,分别用pool为1000的协程和64个线程来跑,结果是多线程的速度是协程的10倍以上. 一个简单的协程例子 #!/usr/bi ...

  9. css中border画三角形

    <!doctype html><html lang="en"> <head>  <meta charset="UTF-8&quo ...

  10. poj2441状态压缩dp基础

    /* 给定n头牛,m个谷仓,每头牛只能在一些特定的谷仓,一个谷仓只能有一头牛 问可行的安排方式 dp[i][j]表示前i头牛组成状态j的方案数,状态0表示无牛,1表示有牛 使用滚动数组即可 枚举到第i ...