[omd-commits] OMD Git: omd: cron and logrotate integration

git version control git at mathias-kettner.de
Thu Dec 23 09:03:11 CET 2010


Module: omd
Branch: master
Commit: 62d57c430f887aae334b525f3b3e9366deb5d425
URL:    http://omdistro.org/projects/omd/repository/revisions/62d57c430f887aae334b525f3b3e9366deb5d425

Author: Joerg Linge <pitchfork at pnp4nagios.org>
Date:   Sun Nov 14 17:07:46 2010 +0100

cron and logrotate integration

---

 Makefile                                       |    3 +-
 packages/maintenance/CRONTAB.hook              |   18 +++++++++
 packages/maintenance/Makefile                  |   15 ++++++++
 packages/maintenance/skel/etc/cron.d/logrotate |    4 ++
 packages/maintenance/skel/etc/init.d/crontab   |   47 ++++++++++++++++++++++++
 packages/maintenance/skel/etc/logrotate.conf   |   16 ++++++++
 packages/maintenance/skel/etc/rc.d/99-crontab  |    1 +
 7 files changed, 103 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 1c7e1cf..e50f9a9 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,8 @@ PACKAGES=perl-modules \
          omd \
          pnp4nagios \
          rrdtool \
-         thruk
+         thruk \
+         maintenance
 
 # This file is kept by 'make config' and also may override
 # the list of packages
diff --git a/packages/maintenance/CRONTAB.hook b/packages/maintenance/CRONTAB.hook
new file mode 100644
index 0000000..32a303e
--- /dev/null
+++ b/packages/maintenance/CRONTAB.hook
@@ -0,0 +1,18 @@
+#!/bin/bash
+case "$1" in
+    alias)
+        echo "Initialize site crontab via etc/init.d/crontab"
+    ;;
+    description)
+        cat <<EOF
+Merge all files in etc/cron.d and initialize a site specific crontab.
+EOF
+        ;;
+    default)
+        echo "on"
+    ;;
+    choices)
+        echo "on: Initialize site specific crontabs at boot time"
+        echo "off: Don´t create a site specific crontab"
+    ;;
+esac
diff --git a/packages/maintenance/Makefile b/packages/maintenance/Makefile
new file mode 100644
index 0000000..4478cf9
--- /dev/null
+++ b/packages/maintenance/Makefile
@@ -0,0 +1,15 @@
+include ../../Makefile.omd
+
+NAME = maintenance 
+VERSION = $(OMD_VERSION)
+SHELL = /bin/bash
+
+build:
+
+install:
+	mkdir -p $(DESTDIR)$(OMD_ROOT)/bin
+	install -m 755 merge-crontabs $(DESTDIR)$(OMD_ROOT)/bin
+
+skel:
+
+clean:
diff --git a/packages/maintenance/skel/etc/cron.d/logrotate b/packages/maintenance/skel/etc/cron.d/logrotate
new file mode 100644
index 0000000..cdce1c2
--- /dev/null
+++ b/packages/maintenance/skel/etc/cron.d/logrotate
@@ -0,0 +1,4 @@
+#
+# Daily Logrotate
+#
+0 0 * * * [ -x /usr/sbin/logrotate ] && /usr/sbin/logrotate -s ###ROOT###/tmp/logrotate.state ###ROOT###/etc/logrotate.conf >/dev/null 2>&1
diff --git a/packages/maintenance/skel/etc/init.d/crontab b/packages/maintenance/skel/etc/init.d/crontab
new file mode 100644
index 0000000..3832f3b
--- /dev/null
+++ b/packages/maintenance/skel/etc/init.d/crontab
@@ -0,0 +1,47 @@
+#!/bin/sh
+# 
+# Start only if Crontab is enabled
+. ###ROOT###/etc/omd/site.conf
+if [ "$CONFIG_CRONTAB" != on ] ; then
+    exit 5
+fi
+
+NAME="crontab"
+MERGECRONTABS="###ROOT###/bin/merge-crontabs"
+CROND="###ROOT###/etc/cron.d/*"
+CRONTAB=`which crontab`          
+USER="###SITE###"
+
+# See how we were called.
+case "$1" in
+
+    start)
+	echo -en "Initializing Crontab "
+	${MERGECRONTABS} ${CROND} | $CRONTAB -u $USER - > /dev/null
+        if [ $? -eq 0 ]; then
+            echo "done."
+            exit 0
+	else
+	    echo "failed."
+	    exit 1
+        fi
+        ;;
+
+    stop)
+	echo "Removing Crontab"
+	$CRONTAB -r -u $USER
+        ;;
+
+    restart|reload)
+        $0 stop
+        $0 start
+        ;;
+
+    *)
+        echo "Usage: crontab {start|stop|restart|reload|status}"
+        exit 1
+        ;;
+
+esac
+  
+# End of this script
diff --git a/packages/maintenance/skel/etc/logrotate.conf b/packages/maintenance/skel/etc/logrotate.conf
new file mode 100644
index 0000000..4be8480
--- /dev/null
+++ b/packages/maintenance/skel/etc/logrotate.conf
@@ -0,0 +1,16 @@
+# see "man logrotate" for details
+# rotate log files weekly
+daily
+
+# keep 4 weeks worth of backlogs
+rotate 30
+
+# create new (empty) log files after rotating old ones
+create
+
+# uncomment this if you want your log files compressed
+compress
+
+# packages drop log rotation information into this directory
+include ###ROOT###/etc/logrotate.d
+
diff --git a/packages/maintenance/skel/etc/rc.d/99-crontab b/packages/maintenance/skel/etc/rc.d/99-crontab
new file mode 120000
index 0000000..b384ef4
--- /dev/null
+++ b/packages/maintenance/skel/etc/rc.d/99-crontab
@@ -0,0 +1 @@
+../init.d/crontab
\ No newline at end of file



More information about the omd-commits mailing list