在编写了几个小型守护进程或 Web 应用程序供我个人使用后,我喜欢使用 systemd 管理它们(如果重要的话,我使用的是 Arch Linux)。所以我写了如下的服务文件:
[Unit]
Description=My example daemon
[Service]
Type=forking
User=example_user
ExecStart=/path/to/my_executable
ExecStop=kill -QUIT $MAINPID
PIDFile=/var/run/example/example.pid
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
my_executable 无法写入其PID文件,则无法启动,这通常意味着该目录/var/run/example/
不存在。每次重新启动后都会发生这种情况,因为我有/var/run
一个临时文件。
一种解决方案是以 root 身份启动 my_executable 并在创建其环境后将其降到正确的访问权限,但我对此并不满意,因为我不相信自己会正确执行此操作。
有没有办法让 systemd 在这里做繁重的工作(也许通过指定另一个应该在执行 ExecStart 之前运行的脚本)?什么是最好的方法?
在确定我的小服务器需要防火墙后,我使用ferm为我配置了iptables和ip6tables(这个问题应该被标记为ferm,但我无法创建标记)。
我对 ipv4 和 ipv6 使用相同的规则,但是一旦我设置了防火墙,IPv6 连接(在所有端口上)就会停止工作,我必须降到 IPv4。为什么会这样?
我的 /etc/ferm.conf
domain (ip ip6) table filter {
chain INPUT {
policy DROP;
# connection tracking
mod state state INVALID DROP;
mod state state (ESTABLISHED RELATED) ACCEPT;
# allow local connections
interface lo ACCEPT;
# respond to ping
proto icmp icmp-type echo-request ACCEPT;
# allow SSH connections
proto tcp dport ssh ACCEPT;
# allow all my lovely server stuff
proto tcp dport (http https smtp imap imaps) ACCEPT;
# Teamspeak 3 Server …
Run Code Online (Sandbox Code Playgroud)