追加読書

追加読書

systemd サービスは次のように定義されます。

[Unit]
Description=WebGPS
After=gpsd.service

[Service]
ExecStart=/usr/sbin/daemonize -p /run/gpsd/webgps.pid -o /var/log/webgps.log /usr/bin/python /var/www/gpsd/webgps.py c
TimeoutSec=1200
WorkingDirectory=/run/gpsd
Environment=PYTHONUNBUFFERED=1
RuntimeDirectory=gpsd
RuntimeDirectoryMode=0755
PermissionsStartOnly=true
Type=forking
PIDFile=/run/gpsd/webgps.pid
Restart=on-failure
GuessMainPID=true

#User=www-data
#Group=www-data

StateDirectory=gpsd
StateDirectoryMode=0755

PrivateTmp=true
ProtectSystem=full
ProtectHome=false
NoNewPrivileges=true
PrivateDevices=true
MemoryDenyWriteExecute=true

[Install]
WantedBy=default.target

次に実行しますsystemctl daemon-reload。今まではそんなに良くなった。次: systemctl enable webgps。悪くない。すべてが最初からsystemctl start webgps期待どおりに機能しましたが、次のようになります。

WorkingDirectory=/run/gpsd

作業ディレクトリには次のものが含まれます。

# ll /run/gpsd
insgesamt 4,0K
drwxr-xr-x  2 0 0  60 Feb 27 16:13 ./
drwxr-xr-x 25 0 0 880 Feb 27 16:13 ../
-rw-r--r--  1 0 0   5 Feb 27 16:13 webgps.pid

この実行されたアプリケーションで生成されたファイルを検索すると、そのファイルを見つけることができます/。これはWorkingDirectoryあなたが仮定することはできません:

# ll /
insgesamt 99K
drwxr-xr-x  21 0 0 4,0K Feb 27 16:13 ./
drwxr-xr-x  21 0 0 4,0K Feb 27 16:13 ../
drwxr-xr-x   2 0 0 4,0K Sep  8 06:49 bin/
drwxr-xr-x   3 0 0 2,5K Jan  1  1970 boot/
drwxr-xr-x  16 0 0 3,7K Feb 27 14:35 dev/
drwxr-xr-x 128 0 0  12K Feb 16 06:48 etc/
-rw-r--r--   1 0 0 2,6K Feb 27 16:15 gpsd-c.html
-rw-r--r--   1 0 0 5,3K Feb 27 16:15 gpsd-c.js
drwxr-xr-x   4 0 0 4,0K Apr  8  2019 home/
drwxr-xr-x  16 0 0 4,0K Apr  8  2019 lib/
drwx------   2 0 0  16K Apr  8  2019 lost+found/
drwxr-xr-x   3 0 0 4,0K Apr  8  2019 media/
drwxr-xr-x   2 0 0 4,0K Apr  8  2019 mnt/
drwxr-xr-x   7 0 0 4,0K Apr  8  2019 opt/
dr-xr-xr-x 131 0 0    0 Jan  1  1970 proc/
drwx------   7 0 0 4,0K Feb 27 16:11 root/
drwxr-xr-x  25 0 0  880 Feb 27 16:13 run/
drwxr-xr-x   2 0 0 4,0K Sep 11 00:07 sbin/
drwxr-xr-x   2 0 0 4,0K Apr  8  2019 srv/
dr-xr-xr-x  12 0 0    0 Feb 27 16:08 sys/
drwxrwxrwt  11 0 0 4,0K Feb 27 16:15 tmp/
drwxr-xr-x  11 0 0 4,0K Apr  8  2019 usr/
drwxr-xr-x  12 0 0 4,0K Aug 20  2019 var/

私が見つけることができるすべての状態は同じです。つまり、WorkingDirectoryアプリケーションが実行されているディレクトリです。何が起こっているのか知っていますか?

ベストアンサー1

daemonize「すべてがうまく動作します」は、実際にサービスマネージャで不安定で危険なPIDファイルメカニズムと完全に不要なプログラムを使用する項目の説明ではありません。皮肉なことに、daemonizeこれが問題の原因です。作業ディレクトリが変更されます。

[Service]
ExecStart=/usr/bin/python /var/www/gpsd/webgps.py c
TimeoutSec=1200
WorkingDirectory=/run/gpsd
Environment=PYTHONUNBUFFERED=1
RuntimeDirectory=gpsd
RuntimeDirectoryMode=0755
PermissionsStartOnly=true
Type=simple
Restart=on-failure

#User=www-data
#Group=www-data

StateDirectory=gpsd
StateDirectoryMode=0755

PrivateTmp=true
ProtectSystem=full
ProtectHome=false
NoNewPrivileges=true
PrivateDevices=true
MemoryDenyWriteExecute=true

追加読書

おすすめ記事