PHP script with systemd
I'm new to systemd and I've got issue with script my colleague gave me. This script worked as background process in Debian 7 but doesn't in Debian 8. I decided to rewrite it to systemd.
I have this in chunk8.service
(which is located in /etc/systemd/system
):
[Unit]
Description=Chunk-search Daemon
Requires=mysql.service apache2.service
[Service]
PIDFile=/var/run/chunkrm8.pid
ExecStart=/usr/bin/php /var/www/chunkrm8/task_pool.php > /dev/null 2>/dev/null
Type=forking
KillMode=process
[Install]
WantedBy=multi-user.target
When I reboot the system (or run systemctl start chunk8.service
) I get:
● chunk8.service - Chunk-search Daemon
Loaded: loaded (/etc/systemd/system/chunk8.service; enabled)
Active: failed (Result: timeout) since Tue 2016-04-19 16:21:20 MSK; 1min 1s ago
What I'm doing wrong? Thanks in advance.
Solution 1:
You specified Type=forking
but the program you started never forked within the timeout period, so systemd considered that it hadn't started up properly, killed it, and marked the service as failed.
Are you sure that your process daemonizes itself? It would be quite unusual for a PHP script to do this. Perhaps you should be using Type=simple
instead.