@@ -, +, @@
---
.../debian/univention-s4-connector.init | 87 +++++++++++++++-------
.../modules/univention/s4connector/s4/main.py | 32 ++++----
.../univention-s4-connector | 6 +-
3 files changed, 80 insertions(+), 45 deletions(-)
--- a/branches/ucs-4.0/ucs-4.0-1/services/univention-s4-connector/debian/univention-s4-connector.init
+++ a/branches/ucs-4.0/ucs-4.0-1/services/univention-s4-connector/debian/univention-s4-connector.init
@@ -30,49 +30,86 @@
# /usr/share/common-licenses/AGPL-3; if not, see
# .
-S4CONNECTORPID=/var/run/univention-s4-connector
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="Uniention Samba4 Connector"
+NAME="univention-s4-connector"
+DAEMON="/usr/sbin/$NAME"
+DAEMON_ARGS=
+PIDFILE="/var/run/$NAME"
+SCRIPTNAME="/etc/init.d/$NAME"
-test -x /usr/sbin/univention-s4-connector || exit 0
+test -x "$DAEMON" || exit 0
+. /lib/init/vars.sh
. /lib/lsb/init-functions
+do_start () {
+ start-stop-daemon --start --quiet --pidfile "$PIDFILE" --startas "$DAEMON" --test > /dev/null ||
+ return 1
+ start-stop-daemon --start --quiet --pidfile "$PIDFILE" --startas "$DAEMON" -- $DAEMON_ARGS ||
+ return 2
+}
+
+do_stop () {
+ start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile "$PIDFILE"
+ RETVAL="$?"
+ [ "$RETVAL" = 2 ] && return 2
+ start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --name "main.py"
+ [ "$?" = 2 ] && return 2
+ rm -f "$PIDFILE"
+ return "$RETVAL"
+}
+
case "$1" in
start)
- # check ucr autostart setting
if [ -f "/usr/share/univention-config-registry/init-autostart.lib" ]; then
. "/usr/share/univention-config-registry/init-autostart.lib"
check_autostart s4-connector connector/s4/autostart
- fi
- log_action_msg "Starting univention-s4-connector daemon"
- if start-stop-daemon --start --quiet --pidfile "$S4CONNECTORPID" -a /usr/sbin/univention-s4-connector; then
- log_action_end_msg 0
- else
- log_action_end_msg 1
fi
+ [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+ do_start
+ case "$?" in
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ esac
;;
stop)
- log_action_msg "Stopping univention-s4-connector daemon"
- if start-stop-daemon --stop --retry TERM/300/KILL/5 --quiet --pidfile "$S4CONNECTORPID" -a /usr/sbin/univention-s4-connector; then
- log_action_end_msg 0
- else
- log_action_end_msg 1
- fi
+ [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+ status)
+ status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
;;
restart|force-reload)
- $0 stop
- sleep 2 # give it some time to die
- $0 start
+ log_daemon_msg "Restarting $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1)
+ sleep 2 # give it some time to die
+ do_start
+ case "$?" in
+ 0) log_end_msg 0 ;;
+ 1) log_end_msg 1 ;; # Old process is still running
+ *) log_end_msg 1 ;; # Failed to start
+ esac
+ ;;
+ *)
+ # Failed to stop
+ log_end_msg 1
+ ;;
+ esac
;;
crestart)
- S4CONNECTOR=`cat $S4CONNECTORPID 2>/dev/null`
- if [ -n "$S4CONNECTOR" ]; then
- ps xaw | grep connector | grep -q "$S4CONNECTOR" && $0 restart
- fi
+ pidofproc -p "$PIDFILE" "$daemon" >/dev/null && "$SCRIPTNAME" restart
;;
*)
- echo "Usage: /etc/init.d/univention-s4-connector {start|stop|restart|crestart|force-reload}"
- exit 1
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart|crestart|force-reload}"
+ exit 3
;;
esac
-
+:
--- a/branches/ucs-4.0/ucs-4.0-1/services/univention-s4-connector/modules/univention/s4connector/s4/main.py
+++ a/branches/ucs-4.0/ucs-4.0-1/services/univention-s4-connector/modules/univention/s4connector/s4/main.py
@@ -30,13 +30,18 @@
# License with the Debian GNU/Linux or Univention distribution in file
# /usr/share/common-licenses/AGPL-3; if not, see
# .
+from warnings import filterwarnings
+filterwarnings("ignore")
-
-import sys, string, os, time, signal, shutil
+import sys
+import os
+import time
+import signal
from optparse import OptionParser
import fcntl
-import ldap, traceback
+import ldap
+import traceback
import univention
import univention.s4connector
import univention.s4connector.s4
@@ -55,10 +60,8 @@ if options.configbasename:
CONFIGBASENAME = options.configbasename
STATUSLOGFILE = "/var/log/univention/%s-s4-status.log" % CONFIGBASENAME
-sys.path=['/etc/univention/%s/s4/' % CONFIGBASENAME]+sys.path
-
-
-import mapping
+from imp import load_source
+mapping = load_source('mapping', '/etc/univention/%s/s4/mapping.py' % CONFIGBASENAME)
def daemon(lock_file):
@@ -146,7 +149,7 @@ def connect():
s4_ldap_bindpw=s4_ldap_bindpw[0:-1]
else:
s4_ldap_bindpw=None
-
+
poll_sleep=int(baseConfig['%s/s4/poll/sleep' % CONFIGBASENAME])
s4_init=None
while not s4_init:
@@ -166,7 +169,6 @@ def connect():
print "Warning: Can't initialize LDAP-Connections, wait..."
sys.stdout.flush()
time.sleep(poll_sleep)
- pass
# Initialisierung auf UCS und S4 Seite durchfuehren
@@ -179,12 +181,10 @@ def connect():
ucs_init=True
except ldap.SERVER_DOWN:
print "Can't contact LDAP server during ucs-poll, sync not possible."
- sys.stdout.flush()
+ sys.stdout.flush()
time.sleep(poll_sleep)
s4.open_s4()
s4.open_ucs()
- pass
-
while not s4_init:
try:
@@ -192,11 +192,10 @@ def connect():
s4_init=True
except ldap.SERVER_DOWN:
print "Can't contact LDAP server during ucs-poll, sync not possible."
- sys.stdout.flush()
+ sys.stdout.flush()
time.sleep(poll_sleep)
s4.open_s4()
s4.open_ucs()
- pass
f.close()
retry_rejected=0
@@ -250,7 +249,7 @@ def connect():
except ldap.SERVER_DOWN:
print "Can't contact LDAP server during resync rejected, sync not possible."
connected = False
- sys.stdout.flush()
+ sys.stdout.flush()
change_counter=0
retry_rejected+=1
@@ -285,7 +284,7 @@ def main():
f=open(STATUSLOGFILE, 'w+')
sys.stdout=f
print time.ctime()
-
+
text = ''
exc_info = sys.exc_info()
lines = apply(traceback.format_exception, exc_info)
@@ -304,4 +303,3 @@ def main():
if __name__ == "__main__":
main()
-
--- a/branches/ucs-4.0/ucs-4.0-1/services/univention-s4-connector/univention-s4-connector
+++ a/branches/ucs-4.0/ucs-4.0-1/services/univention-s4-connector/univention-s4-connector
@@ -32,7 +32,7 @@
# before starting the ad connector, generate the mapping file
-cat /etc/univention/connector/s4/mapping | univention-config-registry filter --encode-utf8 >/etc/univention/connector/s4/mapping.py
-
-/usr/bin/python2.7 -W ignore /usr/lib/pymodules/python2.7/univention/s4connector/s4/main.py
+univention-config-registry filter --encode-utf8 /etc/univention/connector/s4/mapping.py
+exec /usr/lib/pymodules/python2.7/univention/s4connector/s4/main.py
+exec python2.7 -m univention.s4connector.s4.main
--