2 # Common functions for PLC startup/shutdown scripts
4 # Mark Huang <mlhuang@cs.princeton.edu>
5 # Copyright (C) 2006 The Trustees of Princeton University
8 export PATH=/sbin:/bin:/usr/bin:/usr/sbin
10 # Source function library
11 . /etc/init.d/functions
13 # Total number of errors
16 # Count the exit status of the last command
19 ERRORS=$(($ERRORS+$?))
25 echo -n "PLC: $*: " >&3
31 if [ $ERRORS -eq 0 ] ; then
39 # Start up a program with a plc_ prefix
44 # See if it's already running. Look *only* at the pid file.
45 if [ -f /var/run/plc_${base}.pid ]; then
47 read line < /var/run/plc_${base}.pid
49 [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
53 [ -n "${pid:-}" -a -z "${force:-}" ] && return
56 # Thierry -- June 18 2007
57 # when invoking, e.g. service plc start httpd from an ssh connection
58 # ssh stupidly hangs when everything is done
59 # it turns out the forked ssh daemon exhibits the following stack at that point
61 # #0 0x001d6402 in __kernel_vsyscall ()
62 # #1 0x003c2e7d in ___newselect_nocancel () from /lib/libc.so.6
63 # #2 0x004387b4 in main () from /usr/sbin/sshd
64 # So I figured the various file descriptors used were not properly closed
65 (exec 3>&- 4>&- ; exec -a plc_${base} $*)
68 if [ -f /var/run/${base}.pid ] ; then
69 mv /var/run/${base}.pid /var/run/plc_${base}.pid
75 # Print IP address of hostname if resolvable
78 python -c 'import socket; import sys; print socket.gethostbyname(sys.argv[1])' $1 2>/dev/null
81 # Forcefully make a symlink
84 mkdir -p $(dirname $2)
89 # Argument(s) or stdin to lowercase stdout
92 if [ ${#*} -ge 1 ] ; then
99 # Argument(s) or stdin to uppercase stdout
102 if [ ${#*} -ge 1 ] ; then
109 # Regenerate configuration files
114 # Regenerate the main configuration file from default values
115 # overlaid with site-specific and current values.
116 # Thierry -- 2007-07-05 : values in plc_config.xml are *not* taken into account here
118 /etc/planetlab/default_config.xml
119 /etc/planetlab/configs/site.xml
122 for file in "${files[@]}" ; do
123 if [ -n "$force" -o $file -nt /etc/planetlab/plc_config.xml ] ; then
124 tmp=$(mktemp /tmp/plc_config.xml.XXXXXX)
125 plc-config --xml "${files[@]}" >$tmp
126 if [ $? -eq 0 ] ; then
127 mv $tmp /etc/planetlab/plc_config.xml
128 chmod 444 /etc/planetlab/plc_config.xml
130 echo "PLC: Warning: Invalid configuration file(s) detected"
137 # Convert configuration to various formats
138 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config ] ; then
139 plc-config --shell >/etc/planetlab/plc_config
141 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config.py ] ; then
142 plc-config --python >/etc/planetlab/plc_config.py
144 if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/php/plc_config.php ] ; then
145 mkdir -p /etc/planetlab/php
146 plc-config --php >/etc/planetlab/php/plc_config.php
150 # Make copies of stdout and stderr. The plc initscript redirects
151 # stdout and stderr to a logfile if -v is not specified.
152 [ ! -e /proc/self/fd/3 ] && exec 3>&1
153 [ ! -e /proc/self/fd/4 ] && exec 4>&2