- add -l contortion so that backgrounded processes can re-open the log
authorMark Huang <mlhuang@cs.princeton.edu>
Wed, 13 Oct 2004 02:35:47 +0000 (02:35 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Wed, 13 Oct 2004 02:35:47 +0000 (02:35 +0000)
  file after it's rotated
- handle SIGHUP: re-open the log file
- print warning if vcached is already running
- setsid to detach from the controlling terminal and close stdout,
  stdin, stderr before forking

scripts/vcached

index 1d83161..67ba17f 100755 (executable)
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (c) 2004  The Trustees of Princeton University (Trustees).
 #
-# $Id: vcached,v 1.4 2004/08/26 16:48:48 mlh-pl_kernel Exp $
+# $Id: vcached,v 1.5 2004/10/12 21:27:15 mlhuang Exp $
 #
 
 # get configuration
 . /etc/vcached.conf
 
 # parse options
-while getopts 'fd' OPT ; do
+while getopts 'fdl:' OPT ; do
     case "$OPT" in
         f) foreground=1 ;;
         d) debug=1 ;;
+       l) exec 1>>$OPTARG ; exec 2>>$OPTARG ;;
     esac
 done
 
 # check if we are already running
-[ -f $pidfile ] && exit 1
+if [ -f $pidfile ] ; then
+    echo "vcached(`cat $pidfile`) already running"
+    exit 1
+fi
 
 # daemonize
 if [ $foreground -eq 0 ] ; then
-    nohup nice -n $nice -- $0 $* -f >>$logfile 2>&1 &
+    nohup setsid nice -n $nice -- $0 $* -f -l $logfile >/dev/null 2>&1 </dev/null &
     exit 0
 fi
 
 # record PID
 trap "rm -f $pidfile ; exit 255" EXIT
+trap "exec 1>>$logfile ; exec 2>>$logfile" HUP
 echo $$ > $pidfile
 
 : ${UTIL_VSERVER_VARS:=$(dirname $0)/util-vserver-vars}