5 # Common functions for PLC startup/shutdown scripts
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
11 export PATH=/sbin:/bin:/usr/bin:/usr/sbin
13 # Source function library
14 . /etc/init.d/functions
16 # Total number of errors
19 # Count the exit status of the last command
22 ERRORS=$(($ERRORS+$?))
28 echo -n "PLC: $*: " >&3
34 if [ $ERRORS -eq 0 ] ; then
42 # Start up a program with a plc_ prefix
47 # See if it's already running. Look *only* at the pid file.
48 if [ -f /var/run/plc_${base}.pid ]; then
50 read line < /var/run/plc_${base}.pid
52 [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
56 [ -n "${pid:-}" -a -z "${force:-}" ] && return
59 # Thierry -- June 18 2007
60 # when invoking, e.g. service plc start httpd from an ssh connection
61 # ssh stupidly hangs when everything is done
62 # it turns out the forked ssh daemon exhibits the following stack at that point
64 # #0 0x001d6402 in __kernel_vsyscall ()
65 # #1 0x003c2e7d in ___newselect_nocancel () from /lib/libc.so.6
66 # #2 0x004387b4 in main () from /usr/sbin/sshd
67 # So I figured the various file descriptors used were not properly closed
68 (exec 3>&- 4>&- ; exec -a plc_${base} $*)
71 if [ -f /var/run/${base}.pid ] ; then
72 mv /var/run/${base}.pid /var/run/plc_${base}.pid
78 # Print IP address of hostname if resolvable
81 python -c 'import socket; import sys; print socket.gethostbyname(sys.argv[1])' $1 2>/dev/null
84 # Forcefully make a symlink
87 mkdir -p $(dirname $2)
92 # Argument(s) or stdin to lowercase stdout
95 if [ ${#*} -ge 1 ] ; then
102 # Argument(s) or stdin to uppercase stdout
105 if [ ${#*} -ge 1 ] ; then
112 # Make copies of stdout and stderr. The plc initscript redirects
113 # stdout and stderr to a logfile if -v is not specified.
114 [ ! -e /proc/self/fd/3 ] && exec 3>&1
115 [ ! -e /proc/self/fd/4 ] && exec 4>&2