为什么 debian 这么恶心不给用 rc.local 了

2018-12-03 19:22:12 +08:00
 jhytxy
现在设置开机启动要怎么做?

网上搜了几个启用 rc.local 的教程都失败了

求问大佬现在 debian 设置开机启动的正确姿势是什么

以及如何找回熟悉的 rc.local
7976 次点击
所在节点    问与答
40 条回复
xlui
2018-12-03 19:30:32 +08:00
这....楼下教吧
trait
2018-12-03 19:30:35 +08:00
systemd ?
ETiV
2018-12-03 19:32:18 +08:00
crontab @reboot

了解一下
jhytxy
2018-12-03 19:33:01 +08:00
https://www.moerats.com/archives/623/

这个做完以后 rc-local 服务是可以启动了
但是重启一遍又没了
hjc4869
2018-12-03 19:33:19 +08:00
sudo apt install initscripts
trys1
2018-12-03 19:36:18 +08:00
请用 systemctl
hjc4869
2018-12-03 19:38:09 +08:00
Sorry 查错了。无视 #5

Debian 的 systemd 有 rc-local.service,应该放一个 /etc/rc.local 之后就能用?
jhytxy
2018-12-03 19:47:49 +08:00
@hjc4869 systemctl status rc-local.service
● rc-local.service - /etc/rc.local
Loaded: loaded (/etc/systemd/system/rc-local.service; enabled)
Active: failed (Result: exit-code) since Mon 2018-12-03 06:30:51 EST; 16min ago
Process: 223 ExecStart=/etc/rc.local start (code=exited, status=127)

Dec 03 06:30:51 107-172-77-132-host systemd[1]: Starting /etc/rc.local...
Dec 03 06:30:51 107-172-77-132-host systemd[1]: rc-local.service: control pr...7
Dec 03 06:30:51 107-172-77-132-host systemd[1]: Failed to start /etc/rc.local.
Dec 03 06:30:51 107-172-77-132-host systemd[1]: Unit rc-local.service entere....
Hint: Some lines were ellipsized, use -l to show in full.
ooh
2018-12-03 19:56:42 +08:00
ooh
2018-12-03 19:59:36 +08:00
@ooh 补充说明:如果发现执行成功,操作却没有执行可以 服务内的脚本 需要 sleep 一会儿
dot2017
2018-12-03 20:02:01 +08:00
做成 service
WordTian
2018-12-03 20:06:15 +08:00
systemctl enable rc-local #设置 rc-local 开机启动
systemctl start rc-local #启动 rc-local

然后在 /etc/rc.local 文件中加命令就完了
jhytxy
2018-12-03 20:26:36 +08:00
笑话我的人有试过吗

每次都是 rc.local 打不开
我用 root 登录的
rc.local 里就一条 node /c9sdk/server.js -w ~/c9sdk/ -l 0.0.0.0 -a
ZE3kr
2018-12-03 20:29:24 +08:00
有执行权限么
jhytxy
2018-12-03 20:31:29 +08:00
@ooh cat /usr/lib/systemd/system/rc.local.service
cat: /usr/lib/systemd/system/rc.local.service: No such file or directory
jhytxy
2018-12-03 20:32:25 +08:00
@ZE3kr 有 设置完第一遍查看状态可以正常启动

重启完就没了
jhytxy
2018-12-03 20:53:38 +08:00
踩了个大坑

国产教程里的 /usr/lib/systemd/system 是不存在于 debian 9 的

debian 9 在 /etc/systemd/system 里
ooh
2018-12-03 20:55:47 +08:00
hulk@test:~$ cat /lib/systemd/system/rc.local.service

# SPDX-License-Identifier: LGPL-2.1+
#
# 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
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

[Install]
WantedBy=multi-user.target

hulk@test:~$ cat /etc/rc.local

#!/bin/bash
sleep 10 && mount -t vboxsf workspace /srv
exit 0

hulk@test:~$ sudo systemctl status rc-local

● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/rc-local.service.d
└─debian.conf
Active: active (exited) since Mon 2018-12-03 12:40:38 UTC; 16min ago
Docs: man:systemd-rc-local-generator(8)
Process: 1001 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

Dec 03 12:40:28 test systemd[1]: Starting /etc/rc.local Compatibility...
Dec 03 12:40:38 test systemd[1]: Started /etc/rc.local Compatibility.
jhytxy
2018-12-03 20:59:08 +08:00
@ooh 重启一遍呢
ooh
2018-12-03 21:08:57 +08:00
@jhytxy 程序不会骗人的,我一年至少也要重启十几次,你 rc.local 代码有问题,贴出来看看

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/513947

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX