From: Hancock, D. (DHANCOCK) <DHA...@ar...> - 2003-12-15 14:56:52
|
I hope the following is helpful. It's a function "daemon" that exists on Linux (Redhat, at least, maybe other SysV init systems, too). It's used to make a backgrounded daemon out of a foreground process, and it looks like it deals with getting the *right* PID. Another possibility is to switch to daemontools, which EXPECTS its managed processes to be foreground processes. Caveat: I'm not using either of these techniques for handling WebKit processes. # A function to start a program. daemon() { # Test syntax. local gotbase= force= local base= user= nice= bg= pid nicelevel=0 while [ "$1" != "${1##[-+]}" ]; do case $1 in '') echo $"$0: Usage: daemon [+/-nicelevel] {program}" return 1;; --check) base=$2 gotbase="yes" shift 2 ;; --check=?*) base=${1#--check=} gotbase="yes" shift ;; --user) user=$2 shift 2 ;; --user=?*) user=${1#--user=} shift ;; --force) force="force" shift ;; [-+][0-9]*) nice="nice -n $1" shift ;; *) echo $"$0: Usage: daemon [+/-nicelevel] {program}" return 1;; esac done # Save basename. [ -z "$gotbase" ] && base=${1##*/} # See if it's already running. Look *only* at the pid file. pid=`pidfileofproc $base` [ -n "${pid:-}" -a -z "${force:-}" ] && return # make sure it doesn't core dump anywhere; while this could mask # problems with the daemon, it also closes some security problems ulimit -S -c 0 >/dev/null 2>&1 # Echo daemon [ "${BOOTUP:-}" = "verbose" -a -z "$LSB" ] && echo -n " $base" # And start it up. if [ -z "$user" ]; then $nice initlog $INITLOG_ARGS -c "$*" else $nice initlog $INITLOG_ARGS -c "su -s /bin/bash - $user -c \"$*\"" fi [ "$?" -eq 0 ] && success $"$base startup" || failure $"$base startup" } Cheers! -- David Hancock | dha...@ar... | 410-266-4384 -----Original Message----- From: Hollis Blanchard [mailto:ho...@pe...] Sent: Monday, December 15, 2003 12:47 AM To: web...@li... Subject: [Webware-discuss] Re: init script bugs (AppServer autoreloads) On Sunday, Dec 14, 2003, at 23:18 US/Central, Hollis Blanchard wrote: > > + su -s /bin/sh -c "$LAUNCH" $WEBKIT_USER >> $LOG 2>&1 & Unfortunately the su causes $! to return a PID for the su process, which disappears instantly. So writing it to /var/run/webkit.pid later in the init script is worthless; what we really want is the PID of $LAUNCH. I guess the trailing & needs to be moved, but I can't figure it out right now. Anyone else? Note that an su command was already present in the script, though commented out. I seem to recall that not working either when I tried it. -Hollis ------------------------------------------------------- This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click _______________________________________________ Webware-discuss mailing list Web...@li... https://lists.sourceforge.net/lists/listinfo/webware-discuss |