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.
What input do you mean? Is it network requests, or stdin? – user1686 – 2018-05-05T20:37:15.533
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 – 2018-05-05T22:21:21.880
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? – ridiculoushat – 2018-05-05T22:49:13.767
Do not add solution in the question. Put it as an answer add mark it as accepted. See: https://superuser.com/help/self-answer
– Toto – 2018-05-06T10:14:53.263Thanks Toto. Will mark it tomorrow when it becomes available. – ridiculoushat – 2018-05-06T11:43:11.887