diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/cobbler | 20 | ||||
-rwxr-xr-x | scripts/cobbler_syslogd | 52 | ||||
-rwxr-xr-x | scripts/cobblersyslogd | 92 | ||||
-rwxr-xr-x | scripts/watcher.py | 63 |
4 files changed, 227 insertions, 0 deletions
diff --git a/scripts/cobbler b/scripts/cobbler new file mode 100755 index 0000000..4aef615 --- /dev/null +++ b/scripts/cobbler @@ -0,0 +1,20 @@ +#!/usr/bin/python + +""" +Wrapper for cobbler + +Copyright 2006, Red Hat, Inc +Michael DeHaan <mdehaan@redhat.com> + +This software may be freely redistributed under the terms of the GNU +general public license. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +""" + +import sys +import cobbler.cobbler as app +sys.exit(app.main()) + diff --git a/scripts/cobbler_syslogd b/scripts/cobbler_syslogd new file mode 100755 index 0000000..86e77e1 --- /dev/null +++ b/scripts/cobbler_syslogd @@ -0,0 +1,52 @@ +#!/usr/bin/python + +""" +Wrapper for cobbler's remote syslog watching daemon. + +Copyright 2006, Red Hat, Inc +Michael DeHaan <mdehaan@redhat.com> + +This software may be freely redistributed under the terms of the GNU +general public license. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +""" + +import sys +import os +import cobbler.syslog_watcher as app + +if __name__ == "__main__": + + ############################################# + # daemonizing code: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 + try: + pid = os.fork() + if pid > 0: + # exit first parent + sys.exit(0) + except OSError, e: + print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror) + sys.exit(1) + + # decouple from parent environment + os.chdir("/") + os.setsid() + os.umask(0) + + # do second fork + try: + pid = os.fork() + if pid > 0: + # print "Daemon PID %d" % pid + sys.exit(0) + except OSError, e: + print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror) + sys.exit(1) + + ################# + + app.main() + diff --git a/scripts/cobblersyslogd b/scripts/cobblersyslogd new file mode 100755 index 0000000..b8bc3f7 --- /dev/null +++ b/scripts/cobblersyslogd @@ -0,0 +1,92 @@ +#!/bin/sh +# +# cobblersyslogd Cobbler kickstart status monitor +# +# chkconfig: 345 99 99 +# description: This is a daemon which monitors and logs remote syslog traffic \ +# from machines being provisioned from cobbler. \ +# See http://cobbler.et.redhat.com +# +# processname: /usr/bin/cobbler_syslogd + +# Sanity checks. +[ -x /usr/bin/cobbler_syslogd ] || exit 0 + +# Source function library. +. /etc/rc.d/init.d/functions + +RETVAL=0 + +start() { + echo -n $"Starting cobbler remote syslog monitor: " + if test -f /var/lock/subsys/cobblersyslogd ; then + echo_failure + echo + return 1 + fi + /usr/bin/cobbler_syslogd + RETVAL=$? + echo_success + echo + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/cobblersyslogd + return $RETVAL +} + + +stop() { + echo -n $"Stopping cobbler remote syslog monitor: " + if ! test -f /var/lock/subsys/cobblersyslogd ; then + echo_failure + echo + return 1 + fi + pkill cobbler_syslogd + RETVAL=$? + rm /var/lock/subsys/cobblersyslogd + echo_success + echo + return $RETVAL +} + +mystatus() { + if test -f /var/lock/subsys/cobblersyslogd ; then + echo "cobbbler_syslogd is running..." + return 0 + fi + echo "cobbler_syslogd is stopped" + echo + return 0 +} + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + mystatus + RETVAL=$? + ;; + restart) + stop + start + ;; + condrestart) + if [ -f /var/lock/subsys/cobblersyslogd ]; then + stop + start + fi + ;; + reload) + echo "can't reload configuration, you have to restart it" + RETVAL=$? + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}" + ;; +esac +exit $RETVAL + diff --git a/scripts/watcher.py b/scripts/watcher.py new file mode 100755 index 0000000..1074458 --- /dev/null +++ b/scripts/watcher.py @@ -0,0 +1,63 @@ +# cobbler mod_python handler for observing kickstart activity +# +# Copyright 2007, Red Hat, Inc +# Michael DeHaan <mdehaan@redhat.com> +# +# This software may be freely redistributed under the terms of the GNU +# general public license. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import time +from mod_python import apache + +def outputfilter(filter): + + + # extract important info + request = filter.req + connection = request.connection + (address,port) = connection.remote_addr + + # open the logfile (directory be set writeable by installer) + logfile = open("/var/log/cobbler/kicklog/%s" % address,"a+") + + log_it = True + if request.the_request.find("cobbler_track") == -1 and request.the_request.find("ctr/") == -1": + log_it = False + + if log_it: + # write the timestamp + t = time.localtime() + seconds = str(time.mktime(t)) + logfile.write(seconds) + logfile.write("\t") + timestr = str(time.asctime(t)) + logfile.write(timestr) + logfile.write("\t") + + # write the IP address of the client + logfile.write(address) + logfile.write("\t") + + # write the filename being requested + logfile.write(request.the_request) + # logfile.write(request.filename) + logfile.write("\n") + + # if requesting this file, don't return it + if request.the_request.find("watcher.py") != -1: + filter.close() + return + + # pass-through filter + s = filter.read() + while s: + filter.write(s) + s = filter.read() + if s is None: + filter.close() + logfile.close() + |