排行榜 统计
  • 文章总数:1057 篇
  • 评论总数:10 条
  • 分类总数:7 个
  • 最后更新:1月2日

Debian 9 Stretch 解决 /etc/rc.local 开机启动问题

本文阅读 1 分钟
首页 技巧杂烩 正文

由于某些软件并没有增加开启启动的服务,很多时候需要手工添加,一般我们都是推荐添加命令到 /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 </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 前面即可,并尝试重启以后试试是否生效了

本文来自投稿,不代表本站立场,如若转载,请注明出处:
-- 展开阅读全文 --
Debian 小内存64M-128M LNMP/LEMP/WordPress一键脚本
« 上一篇 04-19
独服检测硬盘使用时间
下一篇 » 04-19

发表评论

发表评论

作者信息

云外科技
打破技术壁垒,体验云上服务,云外科技致力于本地上云转型升级,大数据、多渠道为您的业务增添色彩!
TA的最新作品

动态快讯

    请配置好页面缩略名选项

热门文章

最多点赞

标签TAG

热评文章