启动后,我试图让Shadon袜s服务器自动运行,我使用了rc.local
文件,但它不起作用。
rc.local
现在是:
/usr/local/bin/ssserver -c /etc/shadowsocks.json -d start
#!/bin/bash
exit 0
a+x
特权添加到/etc/rc/d/rc.local
中。/etc/rc.local -> /etc/rc.d/rc.local
(默认特权777
)固定为建议的这里。但是,rc.local
中的代码在引导时仍然不能工作。结果发现,当系统启动时,rc.local
没有运行。在这里的帮助下,我能够进一步诊断这个问题。
下面是/etc/systemd/system/rc-local.service
文件(我没有更改任何内容):
[Unit]
Description=/etc/rc.d/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
当我执行systemctl enable rc-local
时,会得到以下错误:
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
instance name specified.
我不知道是哪个原因导致了我的情况,因为rc.local
文件非常简单。
发布于 2017-11-18 10:59:38
你rc.local腐败了!
/usr/local/bin/ssserver -c /etc/shadowsocks.json -d start
#!/bin/bash
exit 0
应该是
#!/bin/bash
/usr/local/bin/ssserver -c /etc/shadowsocks.json -d start
exit 0
编辑:
我不知道您的rc.local
系统服务有什么问题。
然而,我会为“影子袜子”创建一个单独的系统单元,这样你就可以开始和停止它.例如,当您想重新加载配置时,您以及其他必须维护服务器的人都知道要重新启动什么服务。
一个样本阴影袜系统的单位文件:
[Unit]
Description=Shadowsocks proxy server
[Service]
User=www-shadow
Group=www-shadow
Type=simple
ExecStart=/usr/local/bin/ssserver -c /etc/shadowsocks/shadowsocks.json -a shadowsocks -v start
ExecStop=/usr/local/bin/ssserver -c /etc/shadowsocks/shadowsocks.json -a shadowsocks -v stop
[Install]
WantedBy=multi-user.target
注意,这里有一个用户www-shadow
来运行代理,该用户是www-shadow
组的成员。为了保持/etc
的整洁,最好创建一个/etc/shadowsocks
目录,并将JSON与其他与暗袜相关的文件放在其中。我从linode.com获得了系统单元文件的基本知识,但是他们希望以根用户的身份运行代理(baaaaaaaaaad) .考虑到它默认使用端口8388
,我怀疑这是必要的。请注意,如果您不为该单元创建一个www-shadow
用户和组,systemd将很高兴地以root
的形式运行该服务(说来话长,显然是设计上的)。
我对暗袜没有经验(我只在代理中使用squid,对socks代理使用ssh ;-)也没有时间查找它,但是在快速查看了一个单元文件之后,它看起来是合理的(除了root
的愚蠢)。
使用rc.local
单元文件(这是为了向后兼容)没有多大意义,imho,您错过了一个ExecStop,您必须记住rc.local是影子袜子.
如果您想要修复rc.local
单元,它必须是755
(chmod 755 /etc/rc.d/rc.local
),没有人想要一个全局可写的守护进程脚本,这可能是它的另一个问题。Imho,systemd并不总是合理的,但我怀疑它会运行一个可写的脚本。
为了安全起见,你能在你的问题中张贴ls -l /etc/rc.d/rc.local
的输出吗?
EDIT2:
哦(我很傻,它一直在那里,我没有注意到),您的单元文件缺少一个[Install]
指令:
[Install]
WantedBy=multi-user.target
发布于 2017-11-15 05:29:26
Fedora 27使用不运行systemd
的/etc/rc.local
在AskUbuntu上有几种解决方案或建议的解决方案
发布于 2017-11-15 02:18:53
要查看/etc/rc.local是否“正在运行”,可以在/etc/rc.local中键入类似的内容
/bin/date >> /root/test.txt
重新启动并查看文件/root/test.txt中是否有日期。
https://unix.stackexchange.com/questions/404544
复制相似问题