export PATH=/sbin:/bin:/usr/bin:/usr/sbin
-# Source function library
-. /etc/init.d/functions
+# covering for former /etc/init.d/functions
+function success() {
+ echo success "$@"
+ true
+}
+
+function failure() {
+ echo failure "$@"
+ false
+}
+
+function action() {
+ local message="$1"; shift
+ echo $message
+ "$@"
+}
# Total number of errors
ERRORS=0
ERRORS=$(($ERRORS+$?))
}
-# Print status header
function dialog () {
echo -n "PLC: $*: " >&3
}
# Print result
function result () {
if [ $ERRORS -eq 0 ] ; then
- success "$*" >&3
+ success "$@" >&3
else
- failure "$*" >&3
+ failure "$@" >&3
fi
echo >&3
}
# See if it's already running. Look *only* at the pid file.
if [ -f /var/run/plc_${base}.pid ]; then
- local line p
- read line < /var/run/plc_${base}.pid
- for p in $line ; do
- [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
- done
+ local line p
+ read line < /var/run/plc_${base}.pid
+ for p in $line ; do
+ [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
+ done
fi
[ -n "${pid:-}" -a -z "${force:-}" ] && return
ret=$?
if [ -f /var/run/${base}.pid ] ; then
- mv /var/run/${base}.pid /var/run/plc_${base}.pid
+ mv /var/run/${base}.pid /var/run/plc_${base}.pid
fi
return $ret
# Argument(s) or stdin to lowercase stdout
function lower () {
if [ ${#*} -ge 1 ] ; then
- tr A-Z a-z <<<$*
+ tr A-Z a-z <<<$*
else
- tr A-Z a-z
+ tr A-Z a-z
fi
}
# Argument(s) or stdin to uppercase stdout
function upper () {
if [ ${#*} -ge 1 ] ; then
- tr a-z A-Z <<<$*
+ tr a-z A-Z <<<$*
else
- tr a-z A-Z
+ tr a-z A-Z
fi
}
# apachectl -V
# Server version: Apache/2.2.22 (Unix)
# <Directory "/usr/share/plc_api/apache">
-# Options +ExecCGI
+# Options +ExecCGI
# Order allow,deny
# Allow from all
# </Directory>
# apachectl -V
# Server version: Apache/2.4.3 (Fedora)
# <Directory "/usr/share/plc_api/apache">
-# Options +ExecCGI
-# Require all granted
+# Options +ExecCGI
+# Require all granted
# </Directory>
function apache_newauth () {
}
function apache_allow () {
if apache_newauth; then
- echo -e "Require all granted"
+ echo -e "Require all granted"
else
- echo -e "Order allow,deny\n Allow from all"
+ echo -e "Order allow,deny\n Allow from all"
fi
}
function apache_forbid () {
if apache_newauth; then
- echo -e "Require all denied"
+ echo -e "Require all denied"
else
- echo -e "Order deny,allow\n Deny from all"
+ echo -e "Order deny,allow\n Deny from all"
fi
}
#
# Source function library and configuration
-. /etc/plc.d/functions
-. /etc/planetlab/plc_config
+source /etc/plc.d/functions
+source /etc/planetlab/plc_config
# Be verbose
set -x
+echo '$1' = $1
+
case "$1" in
start)
- if [ "$PLC_MAIL_ENABLED" != "1" ] ; then
- exit 0
- fi
+ if [ "$PLC_MAIL_ENABLED" != "1" ] ; then
+ exit 0
+ fi
- MESSAGE=$"Starting mail server"
- dialog "$MESSAGE"
+ MESSAGE=$"Starting mail server"
+ dialog "$MESSAGE"
- # Add apache to list of users that can send mail as others
- # without a warning, so that the API can send out mail.
- count=$(grep ^apache /etc/mail/trusted-users|wc -l)
- if [ $count -eq 0 ] ; then
- echo "apache" >>/etc/mail/trusted-users
- fi
+ # Add apache to list of users that can send mail as others
+ # without a warning, so that the API can send out mail.
+ count=$(grep ^apache /etc/mail/trusted-users|wc -l)
+ if [ $count -eq 0 ] ; then
+ echo "apache" >>/etc/mail/trusted-users
+ fi
- (exec 3>&- 4>&- ; service sendmail start)
- check
+ (exec 3>&- 4>&- ; systemctl start sendmail)
+ check
- result "$MESSAGE"
- ;;
+ result "$MESSAGE"
+ ;;
stop)
- MESSAGE=$"Stopping mail server"
- dialog "$MESSAGE"
+ MESSAGE=$"Stopping mail server"
+ dialog "$MESSAGE"
- service sendmail stop
- check
+ systemctl stop sendmail
+ check
- result "$MESSAGE"
- ;;
+ result "$MESSAGE"
+ ;;
esac
exit $ERRORS
You may also save() the configuration. If a file path or object is
not specified, the configuration will be written to the file path
or object that was first loaded.
-
+
plc.save()
plc.save("/etc/planetlab/plc_config.xml")
"""
It looks for filled-in values in the order of, local object (self),
followed by cread (read values), and finally default values.
- Arguments:
+ Arguments:
default configuration
site configuration
if not category.has_key('id') or type(category['id']) not in types.StringTypes:
return
-
+
category_id = category['id'].lower()
if self._variables.has_key(category_id):
for tag in ['name', 'value', 'description']:
if variable.has_key(tag):
self._set_text_of_child(variable_element, tag, variable[tag])
-
+
if category_element.getElementsByTagName('variablelist'):
variablelist_element = category_element.getElementsByTagName('variablelist')[0]
else:
(variable, category) when found
(None, None) otherwise
"""
-
+
for (category_id, (category, variables)) in self._variables.iteritems():
for variable in variables.values():
(id, name, value, comments) = self._sanitize_variable(category_id, variable)
for attribute in ['type']:
if package.has_key(attribute):
packagereq_element.setAttribute(attribute, package[attribute])
-
+
if group_element.getElementsByTagName('packagelist'):
packagelist_element = group_element.getElementsByTagName('packagelist')[0]
else:
result=get_value (cread,category_id,variable_id)
return result
-# refrain from using plc_config's _sanitize
+# refrain from using plc_config's _sanitize
def get_varname (config, category_id, variable_id):
(category, variable) = config.get (category_id, variable_id)
return (category_id+"_"+variable['id']).upper()
for variable in variables.values():
result += ["%s_%s" %(cid,variable['id'])]
return result
-
+
def print_category (config, cid, show_comments=True):
cid=cid.lower()
CID=cid.upper()
def reload_service ():
global service
- os.system("set -x ; service %s reload" % service)
-
+ os.system("set -x ; systemctl reload %s" % service)
+
####################
def restart_service ():
global service
print ("==================== Stopping %s" % service)
- os.system("service %s stop" % service)
+ os.system("systemctl stop %s" % service)
print ("==================== Starting %s" % service)
- os.system("service %s start" % service)
+ os.system("systemctl start %s" % service)
####################
def prompt_variable (cdef, cread, cwrite, category, variable,
variable_type = get_type(cdef,category_id,variable_id)
current_value = get_current_value(cread,cwrite,category_id, variable_id)
varname = get_varname (cread,category_id, variable_id)
-
+
if show_comments :
print_name_comments (cdef, category_id, variable_id)
prompt = "== %s : [%s] " % (varname,current_value)
except Exception, inst:
if (str(inst) == 'NextCategory'): break
else: raise
-
+
except Exception, inst:
if (str(inst) == 'BailOut'): return
else: raise
print ("Wrote %s" % site_config)
consolidate(default_config, site_config, consolidated_config)
print ("You might want to type 'r' (restart %s), 'R' (reload %s) or 'q' (quit)" % \
- (service,service))
+ (service, service))
elif command in "uU":
global usual_variables
try:
except OSError, e:
print "Cannot create dir %s due to %s - exiting" % (dirname,e)
sys.exit(1)
-
+
if (not os.path.exists (dirname)):
print "Cannot create dir %s - exiting" % dirname
sys.exit(1)
else:
print "Created directory %s" % dirname
-
+
####################
def optParserSetup(configuration):
parser = OptionParser(usage=usage())
# local settings only, will be modified & saved
cwrite=PLCConfiguration()
-
+
try:
cread.load(site_config)
cwrite.load(site_config)