
私はLinux Mintカーネルバージョン4.15.0-42-genericを実行しており、ユーザーのsystemdサービスファイルがあります~/.local/share/systemd/user/my.service
。
[Unit]
Description=My service
After=network.target
After=systemd-user-sessions.service
After=network-online.target
StartLimitBurst=5
StartLimitIntervalSec=30s
[Service]
ExecStart="/my/command"
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=5
PrivateTmp=true
Environment=DISPLAY=:0
[Install]
WantedBy=default.target
インストール方法はファイルを配置した後systemctl --user daemon-reload
、 を実行することですsystemctl --user enable my.service
。
OSがクラッシュしてハード再起動(電源サイクル)を開始しない限り、完全に機能します。再ログイン後、サービスは実行されません。
実は発見すらされていません。
再起動後の最初のコマンドは、ファイルがまだ存在し変更されていないにもかかわらず、systemdがサービスを失ったことを証明します。
matt@brego:~$ systemctl --user status my.service
Unit my.service could not be found.
matt@brego:~$ ls -la ~/.local/share/systemd/user
total 20
drwxr-xr-x 2 matt matt 4096 Oct 16 15:56 .
drwxr-xr-x 3 matt matt 4096 Sep 28 13:58 ..
-rw-r--r-- 1 matt matt 458 Oct 16 15:56 my.service
matt@brego:~$ loginctl list-sessions
SESSION UID USER SEAT TTY
c2 1000 matt seat0
1 sessions listed.
実行中systemctl --user start my.service
またはsystemctl --user enable my.service
同じエラーが発生します。Unit my.service could not be found.
実行しsystemctl --user daemon-reload
、サービスを有効にする必要があります。すべて。時間。後ろに。硬い。再起動。
ユーザーのログイン、システムの再起動、および電源を入れ直した後にsystemdにサービスを実行させるにはどうすればよいですか?そしてサービスも忘れないでください。
追加の質問を解決するために編集
同じユーザーでハード再起動後のさまざまなコマンド出力:
matt@brego:~$ cat /etc/pam.d/systemd-user
# This file is part of systemd.
#
# Used by systemd --user instances.
@include common-account
session required pam_selinux.so close
session required pam_selinux.so nottys open
session required pam_loginuid.so
session required pam_limits.so
@include common-session-noninteractive
session optional pam_systemd.so
matt@brego:~$ ps -U ${UID} -f | grep systemd
matt 1341 1 0 13:34 ? 00:00:00 /lib/systemd/systemd --user
matt 1384 1341 0 13:34 ? 00:00:00 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
matt 6870 1913 0 14:12 pts/1 00:00:00 grep --color=auto systemd
matt@brego:~$ systemctl --user list-units --type=target
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
default.target loaded active active Default
paths.target loaded active active Paths
sockets.target loaded active active Sockets
timers.target loaded active active Timers
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
5 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
matt@brego:~$ systemctl --user status default.target
● default.target - Default
Loaded: loaded (/usr/lib/systemd/user/default.target; static; vendor preset: enabled)
Active: active since Tue 2018-12-04 13:34:34 MST; 38min ago
Docs: man:systemd.special(7)
Dec 04 13:34:34 brego systemd[1341]: Reached target Default.