LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   CentOS 4 (Fedora Core) init script - create PID file (https://www.linuxquestions.org/questions/linux-newbie-8/centos-4-fedora-core-init-script-create-pid-file-462599/)

cejennings_cr 07-10-2006 08:14 AM

CentOS 4 (Fedora Core) init script - create PID file
 
I am trying to write an init script for a shell script and want to know how I can create a PID file for script. I have noticed that in SuSE, there is a function called startproc that accepts a -p option to create a PID file. I have determined that the Redhat/Fedora equivalent to startproc is exec - but this doesn't have a -p option.
This is the SuSE init script that I found as an example to run my shell script:
Code:

#!/bin/bash
#
#
#
# /etc/init.d/syslog2mysql
#

# Comments to support chkconfig on RedHat Linux
# chkconfig: 235 65 35
# description: A very fast and reliable SQL database engine.

### BEGIN INIT INFO
# Provides: syslog2mysql
# Required-Start: $local_fs $network syslog mysql
# Should-Start: syslog mysql
# Required-Stop: $local_fs $network syslog mysql
# Default-Start:  2 3 5
# Default-Stop: 0 1 6
# Short-Description: Start and Stop Syslog2MySQL
# Description: Script to push Syslog data to MySql data base
### END INIT INFO

syslog2mysql_pid="/var/run/syslog2mysql.pid"
syslog2mysql="/var/www/html/phpSyslog-ng/scripts/syslog2mysql.sh"

. /etc/rc.status
rc_reset
case "$1" in
    start)
        test -s ${syslog2mysql_pid} && {
            killproc -p ${syslog2mysql_pid} ${syslog2mysql}
            echo -n "Re-"
        }
        echo -n "Starting syslog2mysql services"
       
        startproc -p ${syslog2mysql_pid} ${syslog2mysql} $params
        ps -C syslog2mysql.sh -o pid= > ${syslog2mysql_pid}
        rc_status -v
        ;;
    stop)
        echo -n "Shutting down syslog2mysql services"
        killproc -p ${syslog2mysql_pid} -TERM ${syslog2mysql} ; rc_status -v
        rm -f ${syslog2mysql_pid}
        ;;
    status)
        echo -n "Checking for service syslog2mysql:"
        checkproc -p ${syslog2mysql_pid}        ${syslog2mysql} ; rc_status -v
        ;;
    *)
        echo "Usage: $0 {start|stop|status}"
        exit 1
        ;;
esac
rc_exit

This is the section I am trying to convert from SuSE to Fedora:

Code:

startproc -p ${syslog2mysql_pid} ${syslog2mysql} $params
ps -C syslog2mysql.sh -o pid= > ${syslog2mysql_pid}

Another side issue - I am looking for any mapping of functions in SuSE to Fedora that can help me with my init scripts. Example: in Fedora what is the equivalent funtion for rc_status in SuSE.

acid_kewpie 07-10-2006 08:22 AM

have you not tried just looking at the existing scripts? precious few better ways to find out how they do it. there are a bunch of functions that sit in /etc/init.d/functions that wrap most of what you are after.


All times are GMT -5. The time now is 07:17 AM.