LinuxQuestions.org
Review your favorite Linux distribution.
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
 
LinkBack Search this Thread
Old 05-11-2013, 06:26 PM   #1
sneakyimp
Member
 
Registered: Dec 2004
Posts: 762

Rep: Reputation: 48
How to launch PHP script at startup on RHEL?


I've got a PHP script I'd like to launch when my RHEL server boots up.

Should I just add this line to /etc/rc.d/rc.local?
Code:
php -q /path/to/my/script.php > /path/to/output.txt
Or is there some better way?
 
Old 05-11-2013, 06:45 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5
Posts: 16,086

Rep: Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993
That would do it, but note it won't shutdown cleanly, it'll probably just get killed.
If you want a more controlled/nice shutdown, copy one of the other scripts in /etc/init.d and adapt it to start & stop your process.
 
1 members found this post helpful.
Old 05-15-2013, 05:32 PM   #3
sneakyimp
Member
 
Registered: Dec 2004
Posts: 762

Original Poster
Rep: Reputation: 48
chrism01, I appreciate your suggestion and am definitely interested in an orderly shut down because my script locks batches of records in a database for processing. Should the server start to shut down, it should unlock any records it has locked so that some other process/machine might work on those records.

I've been looking at the fail2ban init script which looks like it uses bash rather than sh. It's kind of greek to me, though. Any suggestions on where to learn what this stuff means?
Code:
#!/bin/bash
#
# chkconfig: - 92 08
# description: Fail2ban daemon
#              http://fail2ban.sourceforge.net/wiki/index.php/Main_Page
# process name: fail2ban-server
#
#
# Author: Tyler Owen
#

# Source function library.
. /etc/init.d/functions

# Check that the config file exists
[ -f /etc/fail2ban/fail2ban.conf ] || exit 0

FAIL2BAN="/usr/bin/fail2ban-client"

RETVAL=0

getpid() {
    pid=`ps -eo pid,comm | grep fail2ban- | awk '{ print $1 }'`
}

start() {
    echo -n $"Starting fail2ban: "
    getpid
    if [ -z "$pid" ]; then
        $FAIL2BAN -x start > /dev/null
        RETVAL=$?
    fi
    if [ $RETVAL -eq 0 ]; then
        touch /var/lock/subsys/fail2ban
        echo_success
    else
        echo_failure
    fi
    echo
    return $RETVAL
}

stop() {
    echo -n $"Stopping fail2ban: "
    getpid
    RETVAL=$?
    if [ -n "$pid" ]; then
        $FAIL2BAN stop > /dev/null
    sleep 1
    getpid
    if [ -z "$pid" ]; then
        rm -f /var/lock/subsys/fail2ban
        echo_success
    else
        echo_failure
    fi
    else
        echo_failure
    fi
    echo
    return $RETVAL
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        getpid
        if [ -n "$pid" ]; then
                echo "Fail2ban (pid $pid) is running..."
                $FAIL2BAN status
        else
                RETVAL=1
                echo "Fail2ban is stopped"
        fi
        ;;
  restart)
        stop
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|status|restart}"
        exit 1
        ;;
esac

exit $RETVAL
 
Old 05-15-2013, 06:55 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5
Posts: 16,086

Rep: Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993Reputation: 1993
1. compare that with a few others and you'll see a fairly std structure, then you just put your stuff instead of fail2ban etc
2. have a read of this http://www.tldp.org/HOWTO/HighQualit...OWTO/boot.html
 
1 members found this post helpful.
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CentOS 5x - How to launch PHP script Ne0Geek Linux - Newbie 6 04-16-2012 05:48 PM
startup script not working in RHEL 4 shipon_97 Linux - Enterprise 3 08-09-2007 01:13 PM
superkaramba launch at startup marcoguillen Linux - Software 2 03-20-2007 07:38 PM
PHP script to launch at start Black187 Linux - Software 1 04-25-2006 05:13 AM
Howto launch script at startup sendas4 Linux - Newbie 2 03-10-2005 10:51 AM


All times are GMT -5. The time now is 08:31 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