8ad9fddce34a7278a37b837706ed48e971b87447
[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: crond,v 1.7 2007/01/18 22:10:33 mlhuang Exp $
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_BOOT_ENABLED" = "1" ] ; then
46             echo "*/5 * * * * root gen-slices-xml-05.py" >>/etc/cron.d/plc.cron
47             echo "*/15 * * * * root gen-sites-xml.py" >>/etc/cron.d/plc.cron
48             gen-slices-xml-05.py
49             check
50             gen-sites-xml.py
51             check
52         fi
53
54         if [ "$PLC_WWW_ENABLED" = "1" ] ; then
55             echo "*/15 * * * * root gen-static-content.py" >>/etc/cron.d/plc.cron
56             echo "00 * * * * wget -O - -q http://localhost/cron.php" >>/etc/cron.d/plc.cron
57             gen-static-content.py
58             check
59         fi
60
61         if [ "$PLC_DNS_ENABLED" = "1" ] ; then
62             echo "*/15 * * * * root dns-config" >>/etc/cron.d/plc.cron
63             dns-config
64             check
65         fi
66
67         if [ "$PLC_DB_ENABLED" = "1" ] ; then
68             echo "5 5 * * * root vacuumdb -U postgres --all --analyze --quiet" >>/etc/cron.d/plc.cron
69             vacuumdb -U postgres --all --analyze --quiet
70             check
71         fi
72
73         plc_daemon crond
74         check
75
76         result "$MESSAGE"       
77         ;;
78
79     stop)
80         MESSAGE=$"Stopping crond"
81         dialog "$MESSAGE"
82
83         killproc plc_crond
84         check
85
86         result "$MESSAGE"       
87         ;;
88 esac
89
90 exit $ERRORS