[Dev OpenGP] [104] qsdksqhdkq

[ Thread Index | Date Index | More opengp.tuxfamily.org/development Archives ]


Revision: 104
Author:   nicolaf
Date:     2009-03-26 15:55:03 +0100 (Thu, 26 Mar 2009)

Log Message:
-----------
qsdksqhdkq

Modified Paths:
--------------
    trunk/src/bin/ogpdaemon

Added Paths:
-----------
    trunk/src/bin/init.d_daemon


Added: trunk/src/bin/init.d_daemon
===================================================================
--- trunk/src/bin/init.d_daemon	                        (rev 0)
+++ trunk/src/bin/init.d_daemon	2009-03-26 14:55:03 UTC (rev 104)
@@ -0,0 +1,70 @@
+#!/bin/sh -e
+### BEGIN INIT INFO
+# Provides:          ogpdaemon
+# Required-Start:    $local_fs $network 
+# Required-Stop:     $local_fs $network 
+# Default-Start:     S
+# Default-Stop:      0 6
+# Short-Description: Start/stop OGP daemon
+### END INIT INFO
+#
+# ogpdaemon		This init.d script is used to start ogpdaemon.
+#	
+
+PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"
+PIDFILE="/home/nico/ogpdaemon.pid"
+DAEMON="./ogpdaemon"
+NAME="OGP daemon"
+
+
+set -e
+
+error() {
+	echo $1
+	exit 1
+}
+
+case $1 in
+	start)
+		if [ -f "$PIDFILE" ]; then
+			echo "$NAME already running!"
+			exit 1
+		fi
+		echo -n "Starting $NAME... "
+		$DAEMON > $PIDFILE
+		if [ -z `cat "$PIDFILE"` ];then
+			rm "$PIDFILE"
+			error "failed!"
+		fi
+		echo "OK."
+		exit 0
+	;;
+	stop)
+		if [ -f "$PIDFILE" ]; then
+			echo -n "Stopping $NAME... "
+			kill `cat "$PIDFILE"` || error "failed!"
+			rm "$PIDFILE"
+			echo "OK."
+			exit 0
+		fi
+		error "$NAME is not running!"
+	;;
+	restart)
+		$0 stop  || exit 1
+		$0 start || exit 1
+		exit 0
+	;;
+	status)
+		if [ -f "$PIDFILE" ]; then
+			echo "$NAME is running"
+			exit 0
+		else
+			echo "$NAME is not running"
+			exit 0
+		fi
+	;;
+	*)
+		echo "Usage: $0 {start|stop|restart|status}"
+		exit 1
+	;;
+esac


Property changes on: trunk/src/bin/init.d_daemon
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/src/bin/ogpdaemon
===================================================================
--- trunk/src/bin/ogpdaemon	2009-03-26 14:50:37 UTC (rev 103)
+++ trunk/src/bin/ogpdaemon	2009-03-26 14:55:03 UTC (rev 104)
@@ -7,6 +7,7 @@
 from getopt import getopt
 import re
 from time import sleep
+import os
 
 LOG_FILE = '/var/log/ogpdaemon.log'
 CONF_FILE = '/etc/ogpdaemon.conf'
@@ -37,8 +38,6 @@
 		pass
 	
 	currentSOAs = core.pullSOAs(dn)
-	print oldSOAs
-	print currentSOAs
 	if currentSOAs != oldSOAs:
 		f = open(SOAS_FILE, 'w')
 		lines = []
@@ -107,6 +106,9 @@
 	return conf
 
 def save_conf(conf):
+	"""
+		Saves conf to local file.
+	"""
 	f = open(CONF_FILE, 'w')
 	lines = []
 	for k in conf:
@@ -116,64 +118,92 @@
 	f.close()
 
 def installConf(core):
+	"""
+		If LDAP SOAs changed since last time, pull conf from LDAP and install it on local machine
+	"""
 	# if SOAS didnt change, do't do anything
-	print checkSOAs()
 	if not checkSOAs():
 		logging.info("SOAs didn't change, so skipping configuration installation.")
+		if reload:
+			print "SOAs didn't change, so skipping configuration installation."
 		return
+	else:
+		logging.info("SOAs changed, installing conf...")
+		if reload:
+			print "SOAs changed, installing conf..."
 	
 	requiredPlugins=core.getRequiredPlugins(dn)
 	for pluginName in requiredPlugins:
-		if pluginName != 'ogpdaemon':
-			print "Installing conf for plugin '" + pluginName + "'...",
+		if pluginName != 'ogpdaemon': #skip ogpdaemon, because done before
+			if reload: 
+				print "Installing conf for plugin '" + pluginName + "'...",
 			try:
 				pluginClass = Plugin.getPluginFromName(pluginName)
 				pluginInstance = pluginClass(dn)
 				pluginInstance.installConf()
-				print "\033[0;32mOK\033[0m."
+				if reload: 
+					print "\033[0;32mOK\033[0m."
 				logging.info('Configuration installation for plugin %s successful.' % pluginName)
 			except KeyError:
-				print "\033[0;31mfailed\033[0m. Plugin '" + pluginName + "' is missing!"
+				if reload: 
+					print "\033[0;31mfailed\033[0m. Plugin '" + pluginName + "' is missing!"
 				logging.warning('Configuration installation for plugin %s failed. Plugin is missing!' % pluginName)
 			except:
-				print "\033[0;31mfailed\033[0m with %s." % sys.exc_info()[1]
+				if reload: 
+					print "\033[0;31mfailed\033[0m with %s." % sys.exc_info()[1]
 				logging.warning('Configuration installation for plugin %s failed with %s.' % (pluginName, sys.exc_info()[1]))
 						
 
+#initialization
 #getting options from command line
 (reload, loglevel) = parse_opts()
 
-#setting up logging
-logging.basicConfig(filename=LOG_FILE, level=loglevel, format='%(asctime)s %(levelname)-8s %(message)s')
+try:
+	#setting up logging
+	logging.basicConfig(filename=LOG_FILE, level=loglevel, format='%(asctime)s %(levelname)-8s %(message)s')
+	logging.info("OGP Daemon: Starting up...")
+	
+	#getting local conf
+	conf = load_conf()
+	
+	# Connection
+	core = OgpCore(conf['uri'], conf['dn'], conf['passwd'])
+	
+	#loading plugins
+	#should be done AFTER logging configuration
+	from ogp.plugins import *
+	
+	#getting remote conf
+	OgpDaemon  = Plugin.getPluginFromName('ogpdaemon')
+	ogpdaemon  = OgpDaemon(conf['dn'])
+	remoteConf = ogpdaemon.installConf()
+	totalConf = conf.copy()
+	for k in remoteConf:
+			totalConf[k] = remoteConf[k]
+	
+	#if remoteConf overrides uri, dn or passwd, save conf and reinitialize core
+	for k in LOCAL_PARAMETERS:
+		if conf[k] != totalConf[k]:
+			save_conf(totalConf)
+			del core
+			core = OgpCore(totalConf['uri'], totalConf['dn'], totalConf['passwd'])
+			break
+	
+	conf = totalConf
+except:
+	logging.error("OgpDaemon: startup failed with %s" % sys.exc_info()[1])
+	exit(1)
 
-#getting local conf
-conf = load_conf()
+if not reload:
+	try:
+		pid = os.fork()
+	except:
+		print "totopass"
+	
+	if pid != 0:
+		print pid
+		exit(0)
 
-# Connection
-core = OgpCore(conf['uri'], conf['dn'], conf['passwd'])
-
-#loading plugins
-#should be done AFTER logging configuration
-from ogp.plugins import *
-
-#getting remote conf
-OgpDaemon  = Plugin.getPluginFromName('ogpdaemon')
-ogpdaemon  = OgpDaemon(conf['dn'])
-remoteConf = ogpdaemon.installConf()
-totalConf = conf.copy()
-for k in remoteConf:
-		totalConf[k] = remoteConf[k]
-
-#if remoteConf overrides uri, dn or passwd, save conf and reinitialize core
-for k in LOCAL_PARAMETERS:
-	if conf[k] != totalConf[k]:
-		save_conf(totalConf)
-		del core
-		core = OgpCore(totalConf['uri'], totalConf['dn'], totalConf['passwd'])
-		break
-
-conf = totalConf
-
 uri = conf['uri']
 dn = conf['dn']
 passwd = conf['passwd']


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/