c4275c89adaf86b38298b6e0b1fafccc8d8c794a
[myplc.git] / plc.d / crond
1 #!/bin/bash
2 #
3 # priority: 900
4 #
5 # Configure cron jobs
6 #
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
9 #
10 # $Id$
11 #
12
13 # Source function library and configuration
14 . /etc/plc.d/functions
15 . /etc/planetlab/plc_config
16
17 # Be verbose
18 set -x
19
20 # Export so that we do not have to specify -p to psql invocations
21 export PGPORT=$PLC_DB_PORT
22
23 case "$1" in
24     start)
25         MESSAGE=$"Starting crond"
26         dialog "$MESSAGE"
27
28         if [ "$PLC_MAIL_ENABLED" = "1" ] ; then
29             MAILTO=$PLC_MAIL_SUPPORT_ADDRESS
30         else
31             MAILTO=
32         fi
33
34         cat >/etc/cron.d/plc.cron <<EOF
35 SHELL=/bin/bash
36 PATH=/sbin:/bin:/usr/sbin:/usr/bin
37 MAILTO=$MAILTO
38 HOME=/
39 #
40 # minute hour day-of-month month day-of-week user command
41 EOF
42
43         # Run all jobs once at startup
44
45         if [ "$PLC_WWW_ENABLED" = "1" ] ; then
46             echo "00 * * * * wget -O - -q http://localhost/cron.php" >>/etc/cron.d/plc.cron
47             wget -O - -q http://localhost/cron.php
48             check
49         fi
50
51         if [ "$PLC_DNS_ENABLED" = "1" ] ; then
52             echo "*/15 * * * * root dns-config" >>/etc/cron.d/plc.cron
53             dns-config
54             check
55         fi
56
57         if [ "$PLC_DB_ENABLED" = "1" ] ; then
58             echo "5 5 * * * root vacuumdb -U postgres --all --analyze --quiet --full" >>/etc/cron.d/plc.cron
59             vacuumdb -U postgres --all --analyze --quiet
60             check
61         fi
62
63         if [ "$PLC_WWW_ENABLED" = "1" ] ; then
64           echo "*/15 * * * * root clean-empty-dirs.py /var/tmp/bootmedium" >> /etc/cron.d/plc.cron
65           clean-empty-dirs.py /var/tmp/bootmedium
66           check
67         fi
68
69         plc_daemon crond
70         check
71
72         result "$MESSAGE"       
73         ;;
74
75     stop)
76         MESSAGE=$"Stopping crond"
77         dialog "$MESSAGE"
78
79         killproc plc_crond
80         check
81
82         result "$MESSAGE"       
83         ;;
84 esac
85
86 exit $ERRORS