Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1077125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:31:48+00:00 2026-05-16T21:31:48+00:00

I have an init.d script that looks like: #!/bin/bash # chkconfig 345 85 60

  • 0

I have an init.d script that looks like:

#!/bin/bash
# chkconfig 345 85 60
# description: startup script for swapi
# processname: swapi

LDIR=/var/www/html/private/daemon
EXEC=swapi.php
PIDF=/var/run/swapi.pid
IEXE=/etc/init.d/swapi

### BEGIN INIT INFO
# Provides: swapi
# Required-Start: $local_fs
# Required-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: startup script for swapi
# Description: startup script for swapi.php which processes actionq into switch
### END INIT INFO

if [ ! -f $LDIR/$EXEC ]
then
        echo "swapi was not found at $LDIR/$EXEC"
        exit
fi

case "$1" in
  start)
        if [ -f $PIDF ]
        then
                echo "swapi is currently running. Killing running process..."
                $IEXE stop
        fi
        $LDIR/$EXEC >> $LDIR/swapi.log & MYPID=$!
        echo $MYPID > $PIDF
        echo "swapi is now running."
        ;;
  stop)
        if [ -f $PIDF ]
        then
                echo "Stopping swapi."
                PID_2=`cat $PIDF`
                if [ ! -z "`ps -f -p $PID_2 | grep -v grep | grep 'swapi'`" ]
                then
                        kill -9 $PID_2
                fi
                rm -f $PIDF
        else
                echo "swapi is not running, cannot stop it. Aborting now..."
        fi
        ;;
  force-reload|restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Use: /etc/init.d/swapi {start|stop|restart|force-reload}"
        exit 1
esac

And then I have a keepalive cronjob that calls this if the pid goes down. Problem is that that keepalive script hangs whenever I run it like a cron job (ie. run-parts /var/www/html/private/fivemin), (the keepalive script being in /var/www/html/private/fivemin).

Is there something funky in my init.d script that I am missing?

I have been racking my brain on this problem for hours now! I am on centos4 btw.

Thanks for any help.
-Eric

EDIT:

The keepalive/cronjob script was simplified for testing to a simple:

#!/usr/bin/php
<?

exec("/etc/init.d/swapi start");

?>

The strange this is the error output from swapi.php is put into /var/spool/mail like normal cron output except that I have all the output being dumped into the swapi.log in the init.d script?

When I run keepalive.php from the cli (as root from /) it operates exactly as I would expect it to.

When keepalive runs ps aux | grep php looks like:

root      4525  0.0  0.0  5416  584 ?        S    15:10   0:00 awk -v progname=/var/www/html/private/fivemin/keepalive.php progname {?????   print progname ":\n"?????   progname="";????       }????       { print; }
root      4527  0.7  1.4 65184 14264 ?       S    15:10   0:00 /usr/bin/php /var/www/html/private/daemon/swapi.php

And If I do a:

/etc/init.d/swapi stop

from the cli then both programs are no longer listed.

Swapi ls -l looks like:

-rwxr-xr-x  1 5500 5500 33148 Aug 29 15:07 swapi.php

Here is what the crontab looks like:

*/5 * * * * root run-parts /var/www/html/private/fivemin

Here is the first bit of swapi.php

#!/usr/bin/php
<?
chdir(dirname( __FILE__ ));
include("../../config/db.php");
include("../../config/sql.php");
include("../../config/config.php");
include("config_local.php");
include("../../config/msg.php");

include("../../include/functions.php");

set_time_limit(0);
echo "starting @ ".date("Ymd.Gi")."...\n";
$actionstr  =   "";
while(TRUE){

I modified the init.d script and put init above the variable declarations, it did not make a difference.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:31:48+00:00Added an answer on May 16, 2026 at 9:31 pm

    The answer was that bash was staying open because my init.d script was not redirecting the stderr output. I have now changed it to

    $LDIR/$EXEC &> $LDIR/swapi.log & MYPID=$!
    

    And it now functions perfectly.

    Thanks for the help everyone!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.