我有一个~/.config/systemd/user/example.service像这样的用户服务:
[Unit]
Description=Example service
After=network.target
[Service]
ExecStart=/bin/bash -c 'host google.com > /var/tmp/example'
[Install]
WantedBy=default.target
Run Code Online (Sandbox Code Playgroud)
当然,我试图控制的实际服务确实做了一些有用的事情并访问网络;这只是一个简化的例子。
该服务是通过systemctl --user enable example.service它创建~/.config/systemd/user/default.target.wants/example.service指向的符号链接启用的~/.config/systemd/user/example.service。
使用此设置,并systemd按照Arch Wiki 中所述启用用户会话,服务在启动时以我的用户身份启动。但是,实际上并没有在网络建立之后启动;相反,它似乎立即开始,因为/var/tmp/example包含:
;; connection timed out; no servers could be reached
Run Code Online (Sandbox Code Playgroud)
(而且我试图控制的实际服务也无法访问网络,并因类似的名称查找错误而失败)
这意味着该服务实际上并不在network.target. 我如何让它network.target在运行前等待?
我试图让 systemd 做 init.d 脚本会做的事情,在手动给出启动或停止命令后自动显示服务的状态。这有可能吗?
不幸的是,systemd 会立即弹出,因为它在后台运行,然后您必须执行第二个命令来显示状态,启动或停止可能有效,也可能无效,除非您询问并让您幸福地无知,否则 systemd 不会告诉您。
IE。我想得到
service nginx status
在我做完之后自动运行
service nginx start
或者
service nginx restart
(或在大脑受损的 systemd 中, systemctl start nginx.service)
我有一个backup.service每小时调用一次backup.timer。不幸的是,在容器内运行的备份脚本可以成功完成,但警告返回非零退出代码。因此,尽管一切可能都有效,但容器会以非零退出代码停止。因此机组进入故障状态。
在这种情况下,计时器似乎不会再次启动该单元,尽管我在 systemd 文档中没有找到任何内容。
明确地说:对我来说,让容器以非零退出代码停止是完全可以的。但是我的计时器不起作用。
我现在可以将该脚本封装到另一个称为 als docker 入口点的脚本中。但我必须确保以某种方式保留输出 auf STDOUT 和 STDERR。
我也可以在单元失败后运行sudo systemctl reset-failed,但这对我来说似乎有点麻烦......(我试过了,在那种情况下计时器再次运行了单元。但它不能作为 ExecStopPost -服务文件中的任务)
有没有更好的方法来确保一个单位
是否可以更改 systemd 托管服务用于日志记录的标签?例如,我的自定义服务report-daemon.service定义为
# ...
[Service]
ExecStart=/usr/bin/php # ...
# ...
Run Code Online (Sandbox Code Playgroud)
显示为php而不是report-daemon(似乎从 推断标签ExecStart)
$ sudo journalctl --unit report-daemon
# ...
May 30 16:26:11 delta php[994]: Found 0 new revisions for Ctytn4a6zjw
May 30 16:26:12 delta php[994]: Found 0 new revisions for efE8xuvUjAo
# ...
Run Code Online (Sandbox Code Playgroud)
手册页没有列出在单元文件中设置它的任何选项。是否可以在某处更改标签?
如何使用通过带有 systemd-resolved 的 openvpn 服务器推送的 dns ?
在我决定“升级”到 systemd-networkd 之前。我可以使用openvpn-resolv-conf脚本的一些变体来调用 resolvconf 来管理 /etc/resolv.conf 中成功建立 vpn 隧道的条目。
这将允许我在 vpn 隧道的远程端解析名称。
现在 systemd-resolved 管理 /run/systemd/resolved/resolv.conf 是否可以自动将通过 openvpn 连接推送的 DNS 添加到用于解析的名称服务器列表中?
journalctl允许我过滤优先级 ( -p) 并对输出中的优先级进行颜色编码。但是有没有办法让它直接输出优先级,作为文本?
我注意到当我发出reboot命令时,我的 SSH 连接在 CentOS 7 上立即关闭。这并不意味着服务器已经重新启动,因为我仍然可以 ping 它。
似乎 systemd 过早地杀死了 sshd。有时,服务会卡在关闭或缓慢的状态,即使服务器已启动,我也无法再登录以验证出了什么问题。
有没有办法告诉 systemd 在所有其他服务都关闭后才杀死 sshd?
我遇到了一个奇怪的问题。我有一个服务文件来启动自定义应用程序。systemctl 命令显示 LOAD 为未找到
\n\n\n\n\n未找到资源服务-prod-prod.service 活动运行资源-服务-prod-prod.service
\n
但是,文件显示在
\n\nls -lrt /etc/systemd/system\nlrwxrwxrwx 1 root root 96 Mar 5 2017 resource-service-prod.service -> /opt/app/daps-prod/resource-service/bin/resource-service-prod-prod.service\nRun Code Online (Sandbox Code Playgroud)\n\n服务状态显示为正在运行,但已加载:未找到(原因:没有此类文件或目录)
\n\nsudo service resource-service-prod status\nRedirecting to /bin/systemctl status resource-service-prod.service\n\xe2\x97\x8f resource-service-prod-prod.service\n Loaded: not-found (Reason: No such file or directory)\n Active: active (running) since Thu 2018-12-20 06:40:37 CST; 3 weeks 0 days ago\n Main PID: 12888 (node)\n CGroup: /system.slice/resource-service-prod-prod.service\n \xe2\x94\x9c\xe2\x94\x8012888 /usr/bin/node /opt/app/daps-prod/resource-service/source/app.js\n \xe2\x94\x9c\xe2\x94\x8012923 /usr/bin/node /opt/app/daps-prod/resource-service/source/app.js\n \xe2\x94\x9c\xe2\x94\x8012924 /usr/bin/node /opt/app/daps-prod/resource-service/source/app.js\n \xe2\x94\x9c\xe2\x94\x8012930 /usr/bin/node /opt/app/daps-prod/resource-service/source/app.js\n \xe2\x94\x9c\xe2\x94\x8012936 /usr/bin/node /opt/app/daps-prod/resource-service/source/app.js\n \xe2\x94\x9c\xe2\x94\x8012942 …Run Code Online (Sandbox Code Playgroud) 我使用 Fedora 31 并尝试设置 Teamspeak 服务器。当我查看时,journalctl -u teamspeak出现以下错误:
mar 09 22:22:46 melchior systemd[1]: Started Teamspeak server.
mar 09 22:22:46 melchior systemd[20187]: teamspeak.service: Failed to execute command: Permission denied
mar 09 22:22:46 melchior systemd[20187]: teamspeak.service: Failed at step EXEC spawning /srv/teamspeak/3.11.0/ts3server: Permission denied
mar 09 22:22:46 melchior systemd[1]: teamspeak.service: Main process exited, code=exited, status=203/EXEC
mar 09 22:22:46 melchior systemd[1]: teamspeak.service: Failed with result 'exit-code'.
Run Code Online (Sandbox Code Playgroud)
我的 systemd 单元如下所示:
[Unit]
Description=Teamspeak server
After=network-online.target
[Service]
User=teamspeak
Group=teamspeak
WorkingDirectory=/srv/teamspeak/data/
ExecStart=/srv/teamspeak/versions/3.11.0/ts3server dbsqlpath=/srv/teamspeak/versions/3.11.0/sql/ serverquerydocs_path=/srv/teamspeak/versions/3.11.0/serverquerydocs/ license_accepted=1 …Run Code Online (Sandbox Code Playgroud) systemctl cat myunit.service打印主文件的内容myunit.service,然后打印任何覆盖文件。有没有一种方法可以打印 systemd 实际使用的单元文件,即通过将覆盖合并到主单元中而形成的文件?