定义一个 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
Run Code Online (Sandbox Code Playgroud)
然后执行systemctl daemon-reload。到目前为止。下一个:systemctl enable webgps。也没事。开始整个事情systemctl start webgps只是做预期的事情——但是:
WorkingDirectory=/run/gpsd
Run Code Online (Sandbox Code Playgroud)
这个工作目录只包含
# 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
Run Code Online (Sandbox Code Playgroud)
搜索此启动的应用程序创建的文件,我可以在其中找到它们/!这不是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/
Run Code Online (Sandbox Code Playgroud)
我能找到的所有状态都相同:WorkingDirectory是应用程序在其中运行的目录。知道这里发生了什么吗?
对于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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
157 次 |
| 最近记录: |