2

I'm extremely new to systemd and am trying to write a .service file that runs my php script. The script runs and needs to wait for input from someone else to do anything, and remains open til I ctrl-C.

edit: placed this here for clarity on my issue

This service exits immediately after start unless the RemainAfterExit option is set to true. The exit code is 203. With RemainAfterExit, it does not exit but never is running. I am at a loss, I'm afraid.

Here is a generalized version of what I have:

[Unit]   
Description=foo
Wants=foo.service

[Service]   
WorkingDirectory=/home/foo/bar
RemainAfterExit=true
ExecStart=/home/foo/bar/foo.php
Restart=on-failure

[Install]
WantedBy=multi-user-.target

What I want to do:

Start the php script after another required service (Wants/After?)

Keep the php script running, either in a terminal window or the background (simple/forking?)

Don't exit. Restart if it crashes (on-failure). If I want it always to be running, is always appropriate?

If possible, I would prefer reasoning why this service is written poorly/incorrectly and what I need to do instead of fixed code. Links are especially welcome as I'm learning.

5
  • What input do you mean? Is it network requests, or stdin? May 5, 2018 at 20:37
  • I’m having some trouble understanding how your PHP script behaves. If it is designed to be used interactively, it is not suitable to be run as a service. What are you hoping to accomplish by running it as a service? What does it do?
    – Daniel B
    May 5, 2018 at 22:21
  • The script takes something from someone and queries a database on my machine. When I run it, it waits until it receives a message, performs operations on the database, and then returns a value or a confirmation. It never needs me to put input into it. It never requires me to mess with it. In my eyes this qualifies it for a service because it's essentially working with mysql, which runs as a service, and since I want it always running and rebooting when it crashes that seems like a good idea. Maybe it's not. I still want to do it. Can you help? May 5, 2018 at 22:49
  • Do not add solution in the question. Put it as an answer add mark it as accepted. See: superuser.com/help/self-answer
    – Toto
    May 6, 2018 at 10:14
  • Thanks Toto. Will mark it tomorrow when it becomes available. May 6, 2018 at 11:43

1 Answer 1

0

Solved. There were two issues.

Issue 1: ExecStart=/home/foo/bar/foo.php

This needs to be ExecStart=/user/bin/(phpversion) -f /home/foo/bar/foo.php Stupid mistake!

Issue 2: I had to stop the process manually, systemctl stop *.service, systemctl daemon-reload, systemctl start *.service. It ran and my script received/replied to other clients successfully.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .