7751577665a944b12e4ee63b410c7e983de7eff7
[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.6 2006/12/12 22:23:04 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             gen-static-content.py
57             check
58         fi
59
60         if [ "$PLC_DNS_ENABLED" = "1" ] ; then
61             echo "*/15 * * * * root dns-config" >>/etc/cron.d/plc.cron
62             dns-config
63             check
64         fi
65
66         if [ "$PLC_DB_ENABLED" = "1" ] ; then
67             echo "5 5 * * * root vacuumdb -U postgres --all --analyze --quiet" >>/etc/cron.d/plc.cron
68             vacuumdb -U postgres --all --analyze --quiet
69             check
70         fi
71
72         plc_daemon crond
73         check
74
75         result "$MESSAGE"       
76         ;;
77
78     stop)
79         MESSAGE=$"Stopping crond"
80         dialog "$MESSAGE"
81
82         killproc plc_crond
83         check
84
85         result "$MESSAGE"       
86         ;;
87 esac
88
89 exit $ERRORS