LinuxQuestions.org
Visit Jeremy's Blog.
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-28-2017, 09:46 AM   #1
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Rep: Reputation: Disabled
Start process on boot


Trying to start a process on boot for Centos6, and am really struggling. If I have an error, will it be displayed on boot or is it logged somewhere? What am I doing wrong? Thank you

Code:
sudo chmod +x /etc/init.d/test_soap
sudo chkconfig --add test_soap
sudo chkconfig test_soap on

/etc/init.d/test_soap
Code:
#!/bin/sh
### BEGIN INIT INFO
# Provides:          Test SOAP Simulator
# Required-Start:    $local_fs $network $named $time $syslog
# Required-Stop:     $local_fs $network $named $time $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start SOAP Simulator
# Description:       Initiate a given PHP file every 5 seconds to simulate a SOAP server.
### END INIT INFO

SCRIPT= /usr/local/bin/test_soap
RUNAS=root

PIDFILE=/var/run/test_soap.pid
LOGFILE=/var/log/test_soap.log

start() {
  if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE"); then
    echo 'Service already running' >&2
    return 1
  fi
  echo 'Starting service…' >&2
  local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
  su -c "$CMD" $RUNAS > "$PIDFILE"
  echo 'Service started' >&2
}

stop() {
  if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
    echo 'Service not running' >&2
    return 1
  fi
  echo 'Stopping service…' >&2
  kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
  echo 'Service stopped' >&2
}

status() {
    if ps -p $$ > /dev/null
    then
       echo "$prog is running"
    else
       echo "$prog is not running"
    fi
    RETVAL=$?
    return $RETVAL
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    start
    ;;
  status)
    status
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|status}"
esac
/usr/local/bin/test_soap
Code:
/usr/bin/php /var/www/datalogger/test_soap.php
 
Old 04-28-2017, 10:30 AM   #2
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
Code:
SCRIPT= /usr/local/bin/test_soap
pretty sure there shouldn't be a space there. Anyways, no sysvinit doesn't actively check/test if processes are still running and it will be down to yourself to set-up any logging. I personally use either logger or tee -a depending on if you want to use syslog or not.
 
Old 04-28-2017, 11:01 AM   #3
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Original Poster
Rep: Reputation: Disabled
Thanks r3sistance, I will give it a try when I am able, however, as described in my latest post, have bigger problems
 
  


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
Start process at boot with some niceness. s.verma Linux - Newbie 5 12-03-2014 11:21 AM
how to add a process start during the system boot rajesh84210 Linux - General 2 07-27-2009 03:47 AM
Start process at boot frkstein Ubuntu 1 05-15-2005 02:53 PM
Start noip2 process at boot up kt8993 Mandriva 1 05-06-2005 11:47 PM
eth0 wont start with boot process Splin Linux - Networking 3 04-13-2004 06:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:40 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration