4

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.

maaboo
  • 76
  • 1
  • 3
  • What does `systemctl status chunk8.service` return? When you run `/usr/bin/php /var/www/chunkrm8/task_pool.php > /dev/null 2>/dev/null` (or `sudo /usr/bin/php /var/www/chunkrm8/task_pool.php > /dev/null 2>/dev/null`) does your terminal return, or does it sit there spitting out logs and details for the service? – GregL Apr 19 '16 at 15:01
  • I've changed Type and now I'm getting: `root@debian84:~# systemctl status chunk8.service` `● chunk8.service - Chunk-search Daemon` `Loaded: loaded (/etc/systemd/system/chunk8.service; enabled)` `Active: active (running) since Wed 2016-04-20 11:24:03 MSK; 2s ago` `Main PID: 4116 (php)``CGroup: /system.slice/chunk8.service` `└─4116 /usr/bin/php /var/www/chunkrm8/task_pool.php > /dev/null 2>/dev/null` But stopping is still an issue. – maaboo Apr 20 '16 at 08:26

1 Answers1

6

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.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • It helped with start but I still have problem with stopping. It takes too long and I've got these lines with journalctl -xn: `systemd[1]: chunk8.service stop-sigterm timed out. Killing. systemd[1]: chunk8.service: main process exited, code=killed, status=9/KILL systemd[1]: Unit chunk8.service entered failed state.` – maaboo Apr 20 '16 at 06:59