0

openSuSE 13.2 when it's finished starting up I want to automatically run a php script and keep it running in the background. The script is a loop that never ends.. so once launched it shouldn't stop.

It doesn't need to write out any information to screen it will take care of that and generate it's own log file and emails as needed.

In the past I've used the following with bash scripts, but it doesn't work for php. I don't see this as a duplicate question as they relate to bash scripts etc NOT PHP.

- cp <yourscriptname> /etc/init.d/
- insserv <yourscriptname>

chkconfig --list | grep <yourscriptname>

Can anyone advise the best way to do this.

Thanks

Rocket
  • 1,065
  • 2
  • 21
  • 44
  • Possible duplicate of [Run automatically program on startup under linux ubuntu](http://stackoverflow.com/questions/7221757/run-automatically-program-on-startup-under-linux-ubuntu) – André Roggeri Campos Jul 05 '16 at 12:41
  • I would use something like supervisord to start / restart / monitor the process. – jeroen Jul 05 '16 at 12:42
  • @AndréRoggeriCampos - This isn't a duplicate as the other questions relate to bash scripts etc, NOT PHP – Rocket Jul 05 '16 at 12:45

1 Answers1

1

You can make your php script executable. The way is to add #!/usr/bin/php (or whatever your php path is) to the top of the script, and then chmod +x <script>

Then your original solution should work

Chris Lear
  • 6,592
  • 1
  • 18
  • 26
  • When I try this and start it it fails.. `Failed to start test.php.service: Unit test.php.service failed to load: No such file or directory.` What am I doing wrong. – Rocket Jul 05 '16 at 13:06
  • And does it all execute and run correctly even if PATH is unset? – Chris Lear Jul 05 '16 at 13:09
  • Does the filename have a space? Maybe remove it. The non-found file seems to be `Unit test.php.service`, and I'm not sure what is looking for that, or why it doesn't have a path associated. – Chris Lear Jul 05 '16 at 13:23
  • I've got this working. created a file called `test` in `/etc/init.d ` containing `#!/bin/sh /usr/bin/php /home/rocket/Downloads/test.php &`, `chmod +x` it and then `insserv test` now seems to be working. – Rocket Jul 05 '16 at 13:28