2

Defined a systemd service:

[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

Then executed systemctl daemon-reload. Allok so far. Next: systemctl enable webgps. Was ok too. Starting the whole thing with systemctl start webgps just does what is expected -- BUT:

WorkingDirectory=/run/gpsd

This working directory only holds

# 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

Searching for files this started application creates I could find them within /! This is not what WorkingDirectory lets you assume:

# 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/

All I could find about states the same: WorkingDirectory is the directory the application is run within. Any idea what is going on here?

  • 1
    Welcome to the site. For completeness' sake, please edit your post to indicate what OS flavour and version you are using; this kind of information may help to point you in the right direction. – AdminBee Feb 27 at 15:30
7

"All ok" is not really the description that comes to mind for something that uses the rickety and dangerous PID file mechanism, and the wholly unnecessary daemonize program, under a service manager. Ironically, daemonize is the cause of your problem. It is changing the working directory on you.

[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

Further reading

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.