On Monday, Dec 15, 2003, at 08:58 US/Central, Hancock, David (DHANCOCK)
wrote:
> 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.
I'll look closer, but it doesn't seem this script is saving the pid
file anywhere. It checks for a pid file to see if the daemon is already
running, so perhaps it expects the daemon to write one itself...
-Hollis
> # 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 | dhancock@... | 410-266-4384
>
>
> -----Original Message-----
> From: Hollis Blanchard [mailto:hollis@...]
> Sent: Monday, December 15, 2003 12:47 AM
> To: webware-discuss@...
> 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
|