Systemd:修订间差异
跳到导航
跳到搜索
此页面具有访问限制。如果您看见此消息,则说明您没有权限访问此页面。
(→設定) |
(→範例) |
||
(未显示同一用户的9个中间版本) | |||
第13行: | 第13行: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
export XDG_RUNTIME_DIR=/run/user/$(id -u) | [ -z ${XDG_RUNTIME_DIR} ] && export XDG_RUNTIME_DIR=/run/user/$(id -u) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
第27行: | 第27行: | ||
[Service] | [Service] | ||
#Environment="HTTP_PROXY=http://127.0.0.1:3128/" | |||
#Environment="HTTPS_PROXY=http://127.0.0.1:3128/" | |||
ExecStart=/usr/bin/spawn-fcgi | ExecStart=/usr/bin/spawn-fcgi | ||
#ExecStop=... | |||
#KillSignal=SIGQUIT # Default is SIGTERM | |||
Restart=on-failure | Restart=on-failure | ||
RestartSec=60 | RestartSec=60 | ||
Type=simple | Type=simple | ||
#WorkingDirectory= | |||
[Install] | [Install] | ||
第44行: | 第49行: | ||
[Service] | [Service] | ||
#Environment="HTTP_PROXY=http://127.0.0.1:3128/" | |||
#Environment="HTTPS_PROXY=http://127.0.0.1:3128/" | |||
ExecStart=/usr/bin/spawn-fcgi | ExecStart=/usr/bin/spawn-fcgi | ||
#ExecStop=... | |||
#KillSignal=SIGQUIT # Default is SIGTERM | |||
Restart=on-failure | Restart=on-failure | ||
RestartSec=60 | RestartSec=60 | ||
Type=simple | Type=simple | ||
#WorkingDirectory= | |||
[Install] | [Install] | ||
WantedBy=default.target | WantedBy=default.target | ||
</syntaxhighlight> | </syntaxhighlight> | ||
對於<code>Type</code>的選擇<ref>{{Cite web |url=https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type= |title=systemd.service |language=en |accessdate=2023-10-16}}</ref>,常用的有<code>simple</code>(繼續執行)與<code>forking</code>(類似daemon mode)。 | |||
== 參考文獻 == | |||
{{Reflist|2}} | |||
== 外部連結 == | == 外部連結 == |
2024年1月23日 (二) 10:07的最新版本
systemd是一个系统套件。
设定
system模式下不需要额外设定就可以用,建议将自制的service档案装到/etc/systemd/system
下;user模式下需要针对特定使用者启动user自己的systemd:
sudo loginctl enable-linger foo
另外在~/.profile
内可能会需要指定XDG_RUNTIME_DIR
:
[ -z ${XDG_RUNTIME_DIR} ] && export XDG_RUNTIME_DIR=/run/user/$(id -u)
范例
这是一个很简单的范例,放在/etc/systemd/system/
下:
#
[Unit]
Description=Description
After=remote-fs.target
[Service]
#Environment="HTTP_PROXY=http://127.0.0.1:3128/"
#Environment="HTTPS_PROXY=http://127.0.0.1:3128/"
ExecStart=/usr/bin/spawn-fcgi
#ExecStop=...
#KillSignal=SIGQUIT # Default is SIGTERM
Restart=on-failure
RestartSec=60
Type=simple
#WorkingDirectory=
[Install]
WantedBy=multi-user.target
这是user模式下的(因为user模式下没有multi-user.target
,也不需要remote-fs.target
),放在~/.config/systemd/user/
下:
#
[Unit]
Description=Description
[Service]
#Environment="HTTP_PROXY=http://127.0.0.1:3128/"
#Environment="HTTPS_PROXY=http://127.0.0.1:3128/"
ExecStart=/usr/bin/spawn-fcgi
#ExecStop=...
#KillSignal=SIGQUIT # Default is SIGTERM
Restart=on-failure
RestartSec=60
Type=simple
#WorkingDirectory=
[Install]
WantedBy=default.target
对于Type
的选择[1],常用的有simple
(继续执行)与forking
(类似daemon mode)。
参考文献
- ↑ systemd.service. [2023-10-16] (English).
外部连结
- 官方网站 (英文)