Systemd サービスが停止しないBefore=suspens.target

Systemd サービスが停止しないBefore=suspens.target

systemdサービスの実行に問題があります今後状態suspend.targetなのに動作しません。代わりに、systemdサービスが正常に動作しているようです。後ろに suspend.target私が何をしているのか。いろいろ試してみましたが、何を探すべきかわかりません。

これが私が現在持っているものです:

  • "基本"サービスファイル、Pythonスクリプトを実行する:

    python_service.service:

    [Unit]
    Description=Python Systemd Service
    
    [Service]
    ExecStart=/usr/bin/python3 /home/user/python_service.py --user "user" --password "password"
    Environment=XAUTHORITY=/home/user/.Xauthority
    Environment=DISPLAY=:0.0
    Environment=PYTHONUNBUFFERED=1
    Restart=on-failure
    RestartSec=5
    User=root
    
    [Install]
    WantedBy=multi-user.target
    
  • これで、サービスを停止して再開するために、次のように実行目的でのみシステムサービスファイルをさらに2つ作成することにしsystemctl stop python_service.serviceましたsystemctl restart python_service.service

    python_service_stop.service:

    [Unit]
    Description=Stop python_service before suspend
    Before=suspend.target
    
    [Service]
    Type=simple
    ExecStart=/bin/systemctl stop python_service.service
    User=root
    
    [Install]
    WantedBy=multi-user.target
    

私が何をしようとしてもいつもサービスの停止後ろに定義されているにもかかわらず、PCはまだ回復しますBefore=suspend.target

今問題は、どうすれば実際にpython_service.service止めることができるのかということです。今後達成するsuspend.target

ベストアンサー1

おすすめ記事