LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 07-10-2006, 09:14 AM   #1
cejennings_cr
LQ Newbie
 
Registered: Jul 2006
Posts: 5

Rep: Reputation: 0
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.
 
Old 07-10-2006, 09:22 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
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.
 
  


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
starting script, init by copy/create file in (samba) folder? muab Linux - General 7 06-22-2005 07:02 PM
Fedora Core 3 to Centos 4 perroduke cAos 2 05-31-2005 11:45 AM
CentOS vs. Fedora Core sebgate20 Linux - Distributions 7 03-07-2005 02:54 PM
Is there a way to make a program create a pid file? blk96gt Slackware 1 10-29-2004 12:59 PM
How can I create a pid file from a backgournd process that I start? Hackiller Linux - General 3 05-12-2004 03:37 PM


All times are GMT -5. The time now is 08:36 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration