View | Details | Raw Unified | Return to bug 1156
Collapse All | Expand All

(-)debian/control (-2 / +14 lines)
 Lines 7-22    Link Here 
7
7
8
Package: univention-net-installer
8
Package: univention-net-installer
9
Architecture: all
9
Architecture: all
10
Depends: univention-client-boot-pxe, syslinux | syslinux-bin, univention-config-registry
10
Depends: univention-client-boot-pxe, syslinux | syslinux-bin, univention-config-registry, univention-net-installer-daemon
11
Conflicts: univention-server-installer (<< 0.3)
11
Conflicts: univention-server-installer (<< 0.3)
12
Description: UCS - automatic profile server installation
12
Description: UCS - automatic profile server installation
13
 This package contain the automatic profile server installation.
13
 This package contains the automatic profile server installation.
14
 .
14
 .
15
 This package is part of Univention Corporate Server (UCS),
15
 This package is part of Univention Corporate Server (UCS),
16
 an integrated, directory driven solution for managing
16
 an integrated, directory driven solution for managing
17
 corporate environments. For more information about UCS,
17
 corporate environments. For more information about UCS,
18
 refer to: http://www.univention.de/
18
 refer to: http://www.univention.de/
19
19
20
Package: univention-net-installer-daemon
21
Architecture: all
22
Depends: python-univention
23
Description: UCS - automatic profile server installation
24
 This package contains a net installer daemon which removes the reinstallation
25
 flag in the ldap directory.
26
 .
27
 This package is part of Univention Corporate Server (UCS),
28
 an integrated, directory driven solution for managing
29
 corporate environments. For more information about UCS,
30
 refer to: http://www.univention.de/
31
20
Package: univention-server-installer
32
Package: univention-server-installer
21
Architecture: all
33
Architecture: all
22
Depends: univention-net-installer
34
Depends: univention-net-installer
(-)debian/univention-net-installer-daemon.init.d (+233 lines)
Line 0    Link Here 
1
#!/bin/sh
2
# Univention Net Installer Daemon
3
#  init script
4
#
5
# Copyright 2010 Univention GmbH
6
#
7
# http://www.univention.de/
8
#
9
# All rights reserved.
10
#
11
# The source code of this program is made available
12
# under the terms of the GNU Affero General Public License version 3
13
# (GNU AGPL V3) as published by the Free Software Foundation.
14
#
15
# Binary versions of this program provided by Univention to you as
16
# well as other copyrighted, protected or trademarked materials like
17
# Logos, graphics, fonts, specific documentations and configurations,
18
# cryptographic keys etc. are subject to a license agreement between
19
# you and Univention and not subject to the GNU AGPL V3.
20
#
21
# In the case you use this program under the terms of the GNU AGPL V3,
22
# the program is provided in the hope that it will be useful,
23
# but WITHOUT ANY WARRANTY; without even the implied warranty of
24
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
# GNU Affero General Public License for more details.
26
#
27
# You should have received a copy of the GNU Affero General Public
28
# License with the Debian GNU/Linux or Univention distribution in file
29
# /usr/share/common-licenses/AGPL-3; if not, see
30
# <http://www.gnu.org/licenses/>.
31
#
32
### BEGIN INIT INFO
33
# Provides:          univention-net-installer-daemon
34
# Required-Start:    $network $local_fs
35
# Required-Stop:
36
# Should-Start:      $named
37
# Should-Stop:
38
# Default-Start:     2 3 4 5
39
# Default-Stop:      0 1 6
40
# Short-Description: Univention Net Installer Daemon
41
# Description:       Service to reset the reinstall flag
42
### END INIT INFO
43
44
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
45
46
DAEMON=/usr/sbin/univention-net-installer-daemon  # Introduce the server's location here
47
NAME="univention-net-installer-daemon"              # Introduce the short server's name here
48
DESC="Univention Net Installer Daemon" # Introduce a short description here
49
LOGDIR=/var/log/univention # Log directory to use
50
51
PIDFILE=/var/run/$NAME.pid
52
53
test -x "$DAEMON" || exit 0
54
55
. /lib/lsb/init-functions
56
57
# Default options, these can be overriden by the information
58
# at /etc/default/$NAME
59
DAEMON_OPTS="-p 49173 -D -d 1"        # Additional options given to the server
60
61
DIETIME=10              # Time to wait for the server to die, in seconds
62
                        # If this value is set too low you might not
63
                        # let some servers to die gracefully and
64
                        # 'restart' will not work
65
66
STARTTIME=2            # Time to wait for the server to start, in seconds
67
                        # If this value is set each time the server is
68
                        # started (on start or restart) the script will
69
                        # stall to try to determine if it is running
70
                        # If it is not set and the server takes time
71
                        # to setup a pid file the log message might 
72
                        # be a false positive (says it did not start
73
                        # when it actually did)
74
                        
75
LOGFILE="$LOGDIR/$NAME.log"  # Server logfile
76
77
# Include defaults if available
78
if [ -f "/etc/default/$NAME" ] ; then
79
	. "/etc/default/$NAME"
80
fi
81
82
set -e
83
84
running_pid() {
85
# Check if a given process pid's cmdline matches a given name
86
    pid=$1
87
    name=$2
88
    [ -z "$pid" ] && return 1
89
    [ ! -d /proc/$pid ] &&  return 1
90
    cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|sed -ne 2p |cut -d : -f 1`
91
    # Is this the expected server
92
    [ "$cmd" != "$name" ] &&  return 1
93
    return 0
94
}
95
96
running() {
97
# Check if the process is running looking at /proc
98
    # No pidfile, probably no daemon present
99
    [ ! -f "$PIDFILE" ] && return 1
100
    pid=`cat $PIDFILE`
101
    running_pid $pid "$DAEMON" || return 1
102
    return 0
103
}
104
105
start_server() {
106
	start_daemon -p "$PIDFILE" "$DAEMON" $DAEMON_OPTS
107
	errcode=$?
108
	return $errcode
109
}
110
111
stop_server() {
112
	killproc -p "$PIDFILE" "$DAEMON"
113
	errcode=$?
114
	return $errcode
115
}
116
117
reload_server() {
118
    [ ! -f "$PIDFILE" ] && return 1
119
    pid=pidofproc $PIDFILE # This is the daemon's pid
120
    # Send a SIGHUP
121
    kill -1 $pid
122
    return $?
123
}
124
125
force_stop() {
126
# Force the process to die killing it manually
127
	[ ! -e "$PIDFILE" ] && return
128
	if running ; then
129
		kill -15 $pid
130
	# Is it really dead?
131
		sleep "$DIETIME"s
132
		if running ; then
133
			kill -9 $pid
134
			sleep "$DIETIME"s
135
			if running ; then
136
				echo "Cannot kill $NAME (pid=$pid)!"
137
				exit 1
138
			fi
139
		fi
140
	fi
141
	rm -f "$PIDFILE"
142
}
143
144
145
case "$1" in
146
  start)
147
	log_daemon_msg "Starting $DESC " "$NAME"
148
        # Check if it's running first
149
        if running ;  then
150
            log_progress_msg "apparently already running"
151
            log_end_msg 0
152
            exit 0
153
        fi
154
        if start_server ; then
155
            # NOTE: Some servers might die some time after they start,
156
            # this code will detect this issue if STARTTIME is set
157
            # to a reasonable value
158
            [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time 
159
            if  running ;  then
160
                # It's ok, the server started and is running
161
                log_end_msg 0
162
            else
163
                # It is not running after we did start
164
                log_end_msg 1
165
            fi
166
        else
167
            # Either we could not start it
168
            log_end_msg 1
169
        fi
170
	;;
171
  stop)
172
        log_daemon_msg "Stopping $DESC" "$NAME"
173
        if running ; then
174
            # Only stop the server if we see it running
175
			errcode=0
176
            stop_server || errcode=$?
177
            log_end_msg $errcode
178
        else
179
            # If it's not running don't do anything
180
            log_progress_msg "apparently not running"
181
            log_end_msg 0
182
            exit 0
183
        fi
184
        ;;
185
  force-stop)
186
        # First try to stop gracefully the program
187
        "$0" stop
188
        if running; then
189
            # If it's still running try to kill it more forcefully
190
            log_daemon_msg "Stopping (force) $DESC" "$NAME"
191
			errcode=0
192
            force_stop || errcode=$?
193
            log_end_msg $errcode
194
        fi
195
	;;
196
  restart|force-reload)
197
        log_daemon_msg "Restarting $DESC" "$NAME"
198
		errcode=0
199
        stop_server || errcode=$?
200
        # Wait some sensible amount, some server need this
201
        [ -n "$DIETIME" ] && sleep $DIETIME
202
        start_server || errcode=$?
203
        [ -n "$STARTTIME" ] && sleep $STARTTIME
204
        running || errcode=$?
205
        log_end_msg $errcode
206
	;;
207
  status)
208
209
        log_daemon_msg "Checking status of $DESC" "$NAME"
210
        if running ;  then
211
            log_progress_msg "running"
212
            log_end_msg 0
213
        else
214
            log_progress_msg "apparently not running"
215
            log_end_msg 1
216
            exit 1
217
        fi
218
        ;;
219
  # Use this if the daemon cannot reload
220
  reload)
221
        log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
222
        log_warning_msg "cannot re-read the config file (use restart)."
223
        ;;
224
  *)
225
	N=/etc/init.d/$NAME
226
	echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
227
	exit 1
228
	;;
229
esac
230
231
exit 0
232
# vim:set ft=sh:
233
(-)debian/changelog (+19 lines)
 Lines 1-3    Link Here 
1
univention-server-installer (4.1.2-1) unstable; urgency=low
2
3
  * Set STARTTIME in daemon init script to two seconds.
4
    Ticket #2010090610002701 and Bug #1156
5
6
 -- Stefan Gohmann <gohmann@univention.de>  Tue, 14 Sep 2010 14:40:18 +0200
7
8
univention-server-installer (4.1.1-1) unstable; urgency=low
9
10
  * Add a simple network daemon which removes the reinstall flag, for
11
    example by running the following command:
12
     echo $hostname |  netcat $ldap_master  49173
13
    The daemon will be installed on the net install server by default
14
    but the package (univention-net-installer-daemon) can also be
15
    installed on the DC Master.
16
    Ticket #2010090610002701 and Bug #1156
17
18
 -- Stefan Gohmann <gohmann@univention.de>  Thu, 09 Sep 2010 08:51:41 +0200
19
1
univention-server-installer (4.0.4-1) unstable; urgency=low
20
univention-server-installer (4.0.4-1) unstable; urgency=low
2
21
3
  * Increased size of ramdisk, this is required for amd64 systems
22
  * Increased size of ramdisk, this is required for amd64 systems
(-)debian/rules (+2 lines)
 Lines 66-71    Link Here 
66
66
67
	install -m0755 serverinstallerpxe.py $(D)/usr/lib/univention-directory-listener/system/
67
	install -m0755 serverinstallerpxe.py $(D)/usr/lib/univention-directory-listener/system/
68
	install -m0755 81univention-server-installation.inst $(D)/usr/lib/univention-install/
68
	install -m0755 81univention-server-installation.inst $(D)/usr/lib/univention-install/
69
	install -m0755 univention-net-installer-daemon debian/univention-net-installer-daemon/usr/sbin/univention-net-installer-daemon
69
70
70
71
71
	univention-install-config-registry
72
	univention-install-config-registry
 Lines 80-85    Link Here 
80
	dh_installexamples
81
	dh_installexamples
81
	dh_installmenu
82
	dh_installmenu
82
	dh_installcron
83
	dh_installcron
84
	dh_installinit
83
	dh_installman
85
	dh_installman
84
	dh_installinfo
86
	dh_installinfo
85
	dh_installchangelogs
87
	dh_installchangelogs
(-)debian/univention-net-installer-daemon.dirs (+1 lines)
Line 0    Link Here 
1
usr/sbin/
(-)univention-net-installer-daemon (+138 lines)
Line 0    Link Here 
1
#!/usr/bin/python2.4
2
# -*- coding: utf-8 -*-
3
#
4
# Univention Net Installer Daemon
5
#  UVMM handler
6
#
7
# Copyright 2010 Univention GmbH
8
#
9
# http://www.univention.de/
10
#
11
# All rights reserved.
12
#
13
# The source code of this program is made available
14
# under the terms of the GNU Affero General Public License version 3
15
# (GNU AGPL V3) as published by the Free Software Foundation.
16
#
17
# Binary versions of this program provided by Univention to you as
18
# well as other copyrighted, protected or trademarked materials like
19
# Logos, graphics, fonts, specific documentations and configurations,
20
# cryptographic keys etc. are subject to a license agreement between
21
# you and Univention and not subject to the GNU AGPL V3.
22
#
23
# In the case you use this program under the terms of the GNU AGPL V3,
24
# the program is provided in the hope that it will be useful,
25
# but WITHOUT ANY WARRANTY; without even the implied warranty of
26
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
# GNU Affero General Public License for more details.
28
#
29
# You should have received a copy of the GNU Affero General Public
30
# License with the Debian GNU/Linux or Univention distribution in file
31
# /usr/share/common-licenses/AGPL-3; if not, see
32
# <http://www.gnu.org/licenses/>.
33
34
import sys, os, time
35
import signal
36
import socket
37
import univention.uldap
38
import univention.debug as ud
39
from optparse import OptionParser
40
41
def createDaemon(options):
42
	try:
43
		pid = os.fork()
44
	except OSError, e:
45
		print 'Daemon Mode Error: %s' % e.strerror
46
47
	if (pid == 0):
48
		os.setsid()
49
		signal.signal(signal.SIGHUP, signal.SIG_IGN)
50
		try:
51
			pid = os.fork()
52
		except OSError, e:
53
			print 'Daemon Mode Error: %s' % e.strerror
54
		if (pid == 0):
55
			os.chdir("/")
56
			os.umask(0)
57
		else:
58
			pf=open(options.pidfile, 'w+')
59
			pf.write(str(pid))
60
			pf.close()
61
			os._exit(0)
62
	else:
63
		os._exit(0)
64
65
	try:
66
		maxfd = os.sysconf("SC_OPEN_MAX")
67
	except (AttributeError, ValueError):
68
		maxfd = 256       # default maximum
69
70
	for fd in range(0, maxfd):
71
		try:
72
			os.close(fd)
73
		except OSError:   # ERROR (ignore)
74
			pass
75
76
	os.open("/dev/null", os.O_RDONLY)
77
	os.open("/dev/null", os.O_RDWR)
78
	os.open("/dev/null", os.O_RDWR)
79
80
def getLDAPConnection():
81
	# TODO: check for an alternative binddn
82
	if os.path.exists('/etc/ldap.secret'):
83
		lo = univention.uldap.getAdminConnection()
84
	else:
85
		lo = univention.uldap.getMachineConnection()
86
	return lo
87
88
if __name__ == '__main__':
89
	parser = OptionParser(usage='usage: %prog [options] command')
90
	parser.add_option('-p', '--port',
91
			action='store', dest='port', default="49173", type='int',
92
			help='Port for the daemon [%(default)s]' % {'default':'%default'})
93
	parser.add_option('-P', '--pidfile',
94
			action='store', dest='pidfile', default="/var/run/univention-net-installer-daemon.pid",
95
			help='Path to the pid-file [%(default)s]' % {'default':'%default'})
96
	parser.add_option('-D', '--daemon',
97
			action='store_true', dest='daemonize', default=False,
98
			help='Fork into background')
99
	parser.add_option('-d', '--debug',
100
			action='store', dest='debug_level', default="1", type='int',
101
			help='Debug level (0 to 4)')
102
103
	(options, arguments) = parser.parse_args()
104
105
	ud.init('/var/log/univention/net-installer-daemon.log', 1, 0)
106
	ud.set_level( ud.LDAP, options.debug_level)
107
108
	if options.daemonize:
109
		createDaemon(options)
110
111
	HOST = socket.gethostbyname(socket.gethostname())
112
113
	size = 1024 # max hostname length
114
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
115
	s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
116
	s.bind((HOST,options.port))
117
	s.listen(1) 
118
	while True:
119
		client, address = s.accept()
120
		data = client.recv(size)
121
		if data:
122
			data=data.strip()
123
			try:
124
				lo = getLDAPConnection()
125
				result = lo.search(filter='(&(objectClass=univentionHost)(cn=%s)(univentionServerReinstall=1))' % data)
126
				if len(result) == 0:
127
					ud.debug(ud.LDAP, ud.ERROR, 'The computer object %s was not found. Please remove the reinstall flag manually.' % data)
128
				else:
129
					for r in result:
130
						lo.modify(r[0], [('univentionServerReinstall', '1', '0')])
131
						ud.debug(ud.LDAP, ud.PROCESS, 'The computer object %s (%s) was sucessful modified. ' % (data, r[0]))
132
			except:
133
				time.sleep(1)
134
				# for example bad search filter
135
				pass
136
			
137
		client.close() 
138

Return to bug 1156