1

I have a PHP script I'm trying to create a service for. I've created the service however I can't get it to start. The weird thing is, the exact same service UNIT works on my other server of the same setup. The PHP script is set to be ran daemonized with the -d switch. The command itself works just fine but not through systemd.

This is what I get

● serverio.service - Socket Server Service
   Loaded: loaded (/etc/systemd/system/multi-user.target.wants/serverio.service)
   Active: inactive (dead) since Wed 2017-01-18 23:41:49 UTC; 2s ago
  Process: 22921 ExecStop=/usr/bin/php /opt/sockets/server.php stop (code=exited, status=0/SUCCESS)
  Process: 22917 ExecStart=/usr/bin/php /opt/sockets/server.php start -d (code=exited, status=0/SUCCESS)
 Main PID: 22917 (code=exited, status=0/SUCCESS)

Jan 18 23:41:49 hostname systemd[1]: Started SocketIO Server Service.
Jan 18 23:41:49 hostname systemd[1]: Starting SocketIO Server Service...

Here is my service file.

[Unit]
Description=SocketIO Server Service

[Service]
Type=simple
PIDFile=/opt/sockets/phpio.pid
ExecStart=/usr/bin/php /opt/sockets/server.php start -d
ExecStop=/usr/bin/php /opt/sockets/server.php stop

[Install]
WantedBy=multi-user.target

Any idea of on how to get this to work?

Panama Jack
  • 121
  • 1
  • 6
  • If the program daemonizes itself, why have you used `Type=simple`? – Michael Hampton Jan 19 '17 at 00:01
  • It seems to work on the other server using simple. What should I use? When I try forking it just hangs and times out. I know it's starting other processes but the parent seems to remain also so I'm not sure forking is correct either. – Panama Jack Jan 19 '17 at 01:31
  • It seems removing the -d that you use to daemonize it if you run the command from the CLI allows it to start. What I can't understand is why that exact service unit works on my other server. I'm wondering if there is some race condition because I just noticed in the output above it says, Started, then Starting. The order is wrong. Oh well I guess it's resolved. – Panama Jack Jan 19 '17 at 01:47

2 Answers2

1

If all the settings are same on both servers then look at the socket permission

Talal Al-Khalifa
  • 648
  • 5
  • 12
0

Daemonizing your own process with system is an anti-pattern. Removing the daemonizing option is recommended.

Then, since you aren't daemonizing, you shouldn't need the PidFile= option.

Also, you don't need to include Type=simple, since the simple type is the default.

Finally, you likely don't need the ExecStop= line, as systemd will stop the services for you. Search for ExecStop= in man systemd.service to check the details on how that behaves, or try it.

Regarding why the service works on your service: There must be some environmental difference between the two servers. If the systemd unit files are the same, the problem must be elsewhere. Check the logs that your service is generating when it tries to start.

Mark Stosberg
  • 3,771
  • 23
  • 27