LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-13-2005, 08:24 AM   #1
robbiemorgan
LQ Newbie
 
Registered: Aug 2003
Posts: 19

Rep: Reputation: 0
How do I run a PHP script as a service?


Hi all,

I have a PHP script which I need to run as a background process (daemon/service) on my Linux box. I figure it'd be best to set it up like any other service such as httpd and mysql, i.e. so I can go to /etc/init.d and type:

myscript start
myscript stop
myscript status
myscript restart

etc.

Is this the correct way to go about doing this, and if so, how do I do it - can I just copy and modify one of the other scripts?

Also, if I do it this way, is there some guarantee that the script will always be running (providing I add it to one of the rc*.d directories) - i.e. if it fails will the system automatically restart it?

Thanks in advance,

Rob
 
Old 04-13-2005, 11:34 AM   #2
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
Yeah, you can just copy a simplistic startup script and use it for what you want, this is what I have done in the past.

As for restarting it if it dies, I do not believe that this is possible, the service is there just to start it up, not monitor it.
 
Old 04-13-2005, 01:21 PM   #3
robbiemorgan
LQ Newbie
 
Registered: Aug 2003
Posts: 19

Original Poster
Rep: Reputation: 0
Thanks Technoslave. So, any thoughts on how to set up a basic service monitor? i.e. that attempts to restart the service on failure, and sends an e-mail alert?
 
Old 04-13-2005, 02:03 PM   #4
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
I've done something in the past before via a 5 minute cron job, basically it's a simple script that does a ps for the process and if it didn't find it it would restart the app automatically ... this also made it so that I didn't need a startup script as at the next 5 minute mark it would auto-start the app anyway.

Other than that, I don't know ( b/c I haven't looked ) of any app out there that does that type of monitoring, if there is hopefully someone else will let us know.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Priority: script to run on boot vs. "service iptables save" iheardrain Linux - General 5 09-30-2004 09:53 PM
PHP HOWTO : Run script as root guideweb Linux - Software 3 08-22-2004 11:38 PM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 09:34 AM
help getting pptp-php-gtk.php to run as root mrtwice Linux - Software 0 11-21-2003 12:49 PM
Run as Service... tisource Linux - General 2 08-18-2002 04:27 PM


All times are GMT -5. The time now is 06:06 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration