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 # Regenerate configuration files
117 # Regenerate the main configuration file from default values
118 # overlaid with site-specific and current values.
119 # Thierry -- 2007-07-05 : values in plc_config.xml are *not* taken into account here
121 /etc/planetlab/default_config.xml
122 /etc/planetlab/configs/site.xml
125 for file in "${files[@]}" ; do
126 if [ -n "$force" -o $file -nt /etc/planetlab/plc_config.xml ] ; then
127 tmp=$(mktemp /tmp/plc_config.xml.XXXXXX)
128 plc-config --xml "${files[@]}" >$tmp
129 if [ $? -eq 0 ] ; then
130 mv $tmp /etc/planetlab/plc_config.xml
131 chmod 444 /etc/planetlab/plc_config.xml
133 echo "PLC: Warning: Invalid configuration file(s) detected"
140 # Convert configuration to various formats
141 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config ] ; then
142 plc-config --shell >/etc/planetlab/plc_config
144 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config.py ] ; then
145 plc-config --python >/etc/planetlab/plc_config.py
147 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/php/plc_config.php ] ; then
148 mkdir -p /etc/planetlab/php
149 plc-config --php >/etc/planetlab/php/plc_config.php
153 # Make copies of stdout and stderr. The plc initscript redirects
154 # stdout and stderr to a logfile if -v is not specified.
155 [ ! -e /proc/self/fd/3 ] && exec 3>&1
156 [ ! -e /proc/self/fd/4 ] && exec 4>&2