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

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

[email protected] ~ # 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

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

[email protected] ~ # 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

再次查看状态

[email protected] ~ # 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 前面即可,并尝试重启以后试试是否生效了

时间: 2024-08-25 03:14:49

Debian 9.x "stretch" 解决 /etc/rc.local 开机启动问题的相关文章

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

注意:rc.local脚本里面启动的用户默认为root权限. 一.rc.local脚本 rc.local脚本是一个Ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令.该脚本位于/etc/路径下,需要root权限才能修改. 该脚本具体格式如下: #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the scrip

systemd设置rc.local开机启动

systemd 里有 rc-local.service ,只需要再写一个 rc.local 的脚本即可. 1.编辑 /usr/lib/systemd/system/rc-local.service 文件: [Unit] Description=/etc/rc.d/rc.local Compatibility After=network.target [Service] Type=forking ExecStart=/etc/rc.d/rc.local start TimeoutSec=0 Rem

配置rc.local开机自启动文件的疑问

有时我们自己在/etc/rc.d/rc.local里面增加的随机器启动的脚本和指令总是不能自动加载和启动,,机器启动后手动执行脚本又能成功,经常被搞得晕头转向的.最近我经过1天的辛苦测试和查找资料,终于解决了这问题,解决方式如下,/etc/rc.d/rc.local文件的文件头是#!/bin/sh ,我们把这修改成#!/bin/sh -x,这样系统启动后就会把/etc/rc.d/rc.local里面的指令或脚本不能执行的日志写入/var/log/messages ,我们查看messages文件内

centos 7 /etc/rc.local 开机不执行的问题

最近发现centos7 的/etc/rc.local不会开机执行,于是认真看了下/etc/rc.local文件内容的就发现了问题的原因了 #!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using thi

CentOS 6.5 rc.local 开机不执行的原因之一

好久不动Linux,最近帮朋友弄了一下. 新买的阿里云主机,由于内存1GB所以选择了32bit的CentOS6.5. 安装软件和配置及其一些优化都很顺利,可是希望能在开机启动的时候启动web服务器和数据库,我的习惯做法是把启动脚本放在rc.local里面.重启发现根本没生效,测试了一下写法上没有任何问题.但是又找不到问题在哪里,Google了一下没找到什么有用的信息,偶然发现有人在写权限的问题,他写的是即使给了rc.local执行权限仍然无法执行,我看看下是他的脚本写错了.反过来我看了下我的rc

CentOS7 rc.local开机开法启动

CentOS 7添加开机启动服务/脚本 一.添加开机自启服务 在CentOS 7中添加开机自启服务非常方便,只需要两条命令(以Jenkins为例):systemctl enable jenkins.service #设置jenkins服务为自启动服务sysstemctl start  jenkins.service #启动jenkins服务 二.添加开机自启脚本 在centos7中增加脚本有两种常用的方法,以脚本autostart.sh为例:#!/bin/bash#description:开机自

双网卡centos7 iptables防火墙与/etc/rc.d/rc.local开机运行

chmod a+x /etc/rc.d/rc.localvim /etc/rc.d/rc.localecho 1 > /proc/sys/net/ipv4/ip_forwardiptables -Fiptables -Ziptables -Xiptables -t nat -I POSTROUTING -s 内部网络号/子网掩码位数 -o 出口网卡dev名 -j MASQUERADE 原文地址:http://blog.51cto.com/2484643/2106695

rc.local中的memcached命令不执行

碰到了个问题, rc.local 中启动memcached 的命令没有执行, 手动输入却可以. memcached 改成绝对路径之后就好了. 究其原因在于: rc.local 在PATH环境变量指示的路径中寻找 memcached. 在rc.local 执行时, PATH 中还不包括 /usr/local/bin. 手动输入可以, 是因为PATH 中已经包含 /usr/local/bin/ 了. 请写绝对路径. rc.local中的memcached命令不执行,布布扣,bubuko.com

/etc/rc.d/rc.local

/etc/rc.d/rc.local 是启动加载文件,当 Linux 启动时自动加载这个文件 [[email protected] ~]# cat /etc/rc.d/rc.localtouch /var/lock/subsys/local ulimit -SHn 65535 /sbin/sysctl -p /root/memcached_start /root/nrpe_start