長すぎます。

長すぎます。

nfancurve.serviceログインするたびにユーザーサービスを実行したいです。以前は、コマンドを使用してサービスを有効にしていましたが、systemctl --user enable nfancurve.service新しいセッション(再起動を含む)を開始するたびにサービスがアクティブになっても実行されませんでした。ログイン後、次のコマンドを実行してこれを確認しました。

name@machine:~$ systemctl --user is-active nfancurve.service
inactive
name@machine:~$ systemctl --user is-enabled nfancurve.service
enabled
name@machine:~$ systemctl --user start nfancurve.service
name@machine:~$ systemctl --user is-active nfancurve.service
active

以下はステータスログですsystemctl --user status nfancurve.service

● nfancurve.service - Nfancurve service
     Loaded: loaded (/usr/lib/systemd/user/nfancurve.service; enabled; vendor preset: enabled)
     Active: inactive (dead)

完全な情報を得るために、このサービスは以下で提供されます。このリポジトリ、AURからインストールしました。ファイル.serviceは次のとおりです。

[Unit]
Description=Nfancurve service
After=graphical-session.target
Requires=graphical-session.target

[Service]
ExecStart=/bin/sh /usr/bin/nfancurve -c /etc/nfancurve.conf
KillSignal=SIGINT

[Install]
WantedBy=graphical-session.target

最後の行を次に変更してみましたが、再WantedBy=default.target起動してログインしてもサービスはまだ起動しません。私のデスクトップ環境はxfceですgraphical-session.target

ログインするたびに自動的に起動するにはどうすればよいですか?

ベストアンサー1

長すぎます。

に変更WantedBy=graphical-session.targetWantedBy=default.target

仮説

[Install]あなたの問題はサービスファイルセクションにあると思います。システムデバイスの場合はmulti-user.targetインストールによっては問題ありませんが、ユーザーデバイスの場合は同等のインストールですdefault.target。よりsystemd.special(7) マンページもっと学ぶ。

| system target     | near-equivalent user target |
|-------------------|-----------------------------|
| multi-user.target | default.target              |
| graphical.target  | graphical-session.target    |

興味がある他の目標はまたgraphical-session-pre.targetはですxdg-desktop-autostart.target

基本.targetMVCE

以下は、Debian 11システムで試したばかりの最小限の例です。

サービスファイル:

$ systemctl --user cat simpleuser.service
# /home/stew/.config/systemd/user/simpleuser.service
[Unit]
Description=Simple User Service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true

[Install]
WantedBy=default.target

私はそれをインストールした:

$ systemctl --user enable simpleuser.service
Created symlink /home/stew/.config/systemd/user/default.target.wants/simpleuser.service → /home/stew/.config/systemd/user/simpleuser.service.

再起動すると、サービスが有効になっていることがわかります。

$ systemctl --user status simpleuser.service
● simpleuser.service - Simple User Service
     Loaded: loaded (/home/stew/.config/systemd/user/simpleuser.service; enabled; vendor preset: enable>
     Active: active (exited) since Sun 2020-07-12 10:12:54 CEST; 13min left
    Process: 1127 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 1127 (code=exited, status=0/SUCCESS)

Jul 12 10:12:54 stewbian systemd[1106]: Starting Simple User Service...
Jul 12 10:12:54 stewbian systemd[1106]: Finished Simple User Service.

サブステータスを知りたい場合は、次のようなものを(exited)使用して取得できます。Type=simpleExecStart=/bin/sleep infinity(running)

グラフィックセッション目標の質問

バグレポートであなたの問題を発見しました。羽ハブから

graphic-session.target ベースでインストールした場合、起動しないことがあります。私はこれをKDE / i3設定で実行し、デフォルトのGnome3設定で再現しました。

$ systemctl --user status graphical-session.target
● graphical-session.target - Current graphical user session
     Loaded: loaded (/usr/lib/systemd/user/graphical-session.target; static; vendor preset: disabled)
     Active: inactive (dead)
       Docs: man:systemd.special(7)

DEが意図したとおり、実際にこれを達成できないようです。この場合はを使用してくださいWantedBy=default.target。あなたのスクリプトはGUIベースのようには見えないのでdefault.target大丈夫でしょう。それ以外の場合は、セクションAfter=graphical.targetで使用することを検討できます[Unit]

~によるとsystemd.special(7) マンページ、DE(例)でgraphical-session.targetなければなりません。このようにGnomeが起動すると、graphic-session.targetが発生します。 dbus オブジェクトを調べてみると、これを発生させる対象とは何の関係もないことがはっきりわかります。BoundBy={gnome,kde,xfce}-session.target

$ busctl introspect --user org.freedesktop.systemd1 \
    /org/freedesktop/systemd1/unit/graphical_2dsession_2etarget \
    org.freedesktop.systemd1.Unit
NAME                             TYPE      SIGNATURE RESULT/VALUE                             FLAGS
.ActiveState                     property  s         "inactive"                               emits-change
.After                           property  as        2 "simpleuser.service" "basic.target"    const
.Before                          property  as        1 "shutdown.target"                      const
.BindsTo                         property  as        0                                        const
.BoundBy                         property  as        0                                        const
.Conflicts                       property  as        1 "shutdown.target"                      const
.ConsistsOf                      property  as        2 "gnome-terminal-server.service" "duns… const
.Description                     property  s         "Current graphical user session"         const
.Documentation                   property  as        1 "man:systemd.special(7)"               const
.LoadState                       property  s         "loaded"                                 const
.Names                           property  as        1 "graphical-session.target"             const
.PartOf                          property  as        0                                        const
.RequiredBy                      property  as        0                                        const
.Requires                        property  as        1 "basic.target"                         const
.SubState                        property  s         "dead"                                   emits-change
.UnitFilePreset                  property  s         "disabled"                               -
.UnitFileState                   property  s         "static"                                 -
.WantedBy                        property  as        0                                        const
.Wants                           property  as        1 "simpleuser.service"                   const

私はメーリングリストを調べた結果、{gnome,kde,xfce}-session.targetこの提案がわずか4年前にgnome、kde、およびxfceでこれらの*.targetファイルを送信するように作成されたことがわかりました。このようなことはまだ起こっていません。したがって、記録があっても不完全です。したがって、まだ使用しないでくださいgraphical-session.target

おすすめ記事