3

I am trying to setup a systemd service on Ubuntu 15.04 (and Debian 8). I have a program /home/testuser/server/prrserver. My systemd service is configured to run prrserver as testuser:testuser. What the prrserver does is start a new process /home/testuser/server/prrproc which reads some files in /home/testuser/server/data. What is interesting is that prrserver starts OK and prrproc starts OK but prrproc complains that there is no such file /home/testuser/server/data/foo which otherwise exists. If I start my server from the command line, it finds the file. Any idea what could be wrong? Maybe when prrserver forks a new process, the new process doesn't run as testuser anymore and for some reason can't access the testuser directory (even though it's permission allow this)?

[Unit]
Description=PRR Server

[Service]
Type=simple
User=testuser
Group=testuser
ExecStart=/home/testuser/server/prrserver

[Install]
WantedBy=multi-user.target

The status is something like this:

systemctl status prrserver.service
    â prrserver.service - PRR Server
   Loaded: loaded (/lib/systemd/system/prrserver.service; enabled; vendor preset: enabled)
   Active: active (running) since mån 2015-05-25 14:50:42 CEST; 1min 2s ago
 Main PID: 21205 (prrserver)
   CGroup: /system.slice/prrserver.service
           ââ21205 /bin/sh /home/testuser/server/prrserver
           ââ22101 /bin/sh /home/testuser/server/prrproc

maj 25 14:50:42 ubuntu-dev systemd[1]: Started PRR Server.
maj 25 14:50:42 ubuntu-dev systemd[1]: Starting PRR Server...
maj 25 14:50:53 ubuntu-dev prrserver[21205]: PRR Server started listening on port 10239

Note that the main process prrserver launches the prrproc processes and the problem is with the prrproc processes so the status of the service is green.

  • Is it starting as root? The file not found error is from Journalctl? – Thushi May 25 '15 at 11:55
  • I log in as root and then start the service. The forked process dies and its log file I can see that the reason is because it did not find the file. – RegedUser00x May 25 '15 at 12:12
  • 2
    You need to edit your question and show people (a) the service unit contents, and (b) the output of systemctl status prserver.service when run as the superuser (or an adm user). – JdeBP May 25 '15 at 12:27
  • I updated the question. – RegedUser00x May 25 '15 at 13:01
  • 1
    This is a problem only when started at boot? The /home may not yet be mounted at that time. Also, in systemd, there is a concept of user and system sessions - which might be a problem. Another possible problem is whether or not systemd is running the service in a private mount namespace - I cannot recall under what conditions it does so, but definitely in some situations systemd will expose only specific sections of the mount tree to services. But it's the Wanted.By that is the problem, I think. You should add a Wants for local.fs.target. – mikeserv May 25 '15 at 13:09
1

In theory it could be private mount namespace. It's a security feature. I guess you could try ruling it out with

ProtectHome=off

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.