5 # Manage settings for the Zabbix installtion and
6 # other monitor-related things
8 # Stephen Soltesz <soltesz@cs.princeton.edu>
9 # Copyright (C) 2008 The Trustees of Princeton University
14 # Source function library and configuration
15 . /etc/plc.d/functions
16 . /etc/plc.d/monitor.functions
17 . /etc/planetlab/plc_config
18 local_config=/etc/planetlab/configs/site.xml
20 MONITORPATH=/usr/share/monitor
26 PGDATA=/var/lib/pgsql/data
27 postgresql_conf=$PGDATA/postgresql.conf
28 pghba_conf=$PGDATA/pg_hba.conf
30 # Export so that we do not have to specify -p to psql invocations
31 export PGPORT=$PLC_DB_PORT
39 if [ -z "$PLC_RT_IP" ] ; then
40 PLC_RT_IP=$( gethostbyname $PLC_RT_HOST )
44 # TODO: make values re-configurable... this may be an issue with RT's db, though.
45 function update_config ()
50 sed -i -e "s/$pattern/$with/g" $file
53 function check_rt_siteconfig ()
55 tmp_siteconfig=$(mktemp)
56 tmp_initialdata=$(mktemp)
58 # TODO: need a better approach for this.
59 for f in $MONITORPATH/rt3/rtconf.d/*.pl ; do
60 update_config PLC_RT_HOSTNAME $PLC_RT_HOST $f
63 # if the templates are newer than the actual config, then replace them.
64 if [ $MONITORPATH/rt3/RT_SiteConfig.pm -nt /etc/rt3/RT_SiteConfig.pm ] ;
67 cp -f $MONITORPATH/rt3/RT_SiteConfig.pm $tmp_siteconfig
68 cp -f $MONITORPATH/rt3/initialdata $tmp_initialdata
70 # setup RT_SiteConfig.pm
71 update_config PLC_NAME "$PLC_NAME" $tmp_siteconfig
72 update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_siteconfig
74 update_config RT_DB_NAME $RT3_DB_NAME $tmp_siteconfig
75 update_config RT_DB_USER $RT3_DB_USER $tmp_siteconfig
76 update_config RT_DB_PASSWORD $PLC_MONITOR_DBPASSWORD $tmp_siteconfig
79 update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_initialdata
81 # copy to live configuration
82 cp -f $tmp_siteconfig /etc/rt3/RT_SiteConfig.pm
83 cp -f $tmp_initialdata /etc/rt3/initialdata
84 chmod 644 /etc/rt3/RT_SiteConfig.pm
85 chmod 644 /etc/rt3/initialdata
88 rm -f $tmp_initialdata
92 function check_rt_custom ()
94 rsync -qv -az $MONITORPATH/rt3/local/html /usr/share/rt3
97 function check_rt_pghba ()
101 CONF=$PGDATA/pg_hba.conf.d/${NAME}.conf
102 PATTERN="host all postgres 127.0.0.1/32 trust"
104 if ! grep -q "$PATTERN" $CONF ; then
105 #### SETUP ACCESS from postgres user to run init for the first time.
106 echo "$PATTERN" >> $CONF
107 WROTE_PG_CONFIG="true"
112 function check_rt_aliases ()
115 if ! grep -q "rt-mailgate --queue support" /etc/aliases ;
117 sed -i -e "s/^support.*postmaster//g" /etc/aliases
118 sed -i -e "s/^security.*root//g" /etc/aliases
119 cat <<EOF >> /etc/aliases
120 # added by RT init scripts for default queues.
121 support: "|/usr/sbin/rt-mailgate --queue support --action correspond --url http://localhost/rt3/"
122 monitor: "|/usr/sbin/rt-mailgate --queue monitor --action correspond --url http://localhost/rt3/"
123 security: "|/usr/sbin/rt-mailgate --queue security --action correspond --url http://localhost/rt3/"
124 legal: "|/usr/sbin/rt-mailgate --queue legal --action correspond --url http://localhost/rt3/"
131 function check_rt_init ()
133 if [ ! -f /etc/rt3/setup.finished ] ; then
134 /usr/sbin/rt-setup-database --action init --dba postgres
135 for f in $MONITORPATH/rt3/rtconf.d/*.pl ; do
136 /usr/sbin/rt-setup-database --action insert --dba postgres --datafile $f
139 # run initial setup scripts (run only once, or for the first time)
140 for f in $MONITORPATH/rt3/rtsetup.d/*.{pl,py,sh} ; do
144 touch /etc/rt3/setup.finished
151 tmp_sendmailmc=$(mktemp)
153 # if the templates is newer than the processed config, then update it
154 if grep -q "Addr=127.0.0.1," /etc/mail/sendmail.mc ;
157 cp -f /etc/mail/sendmail.mc $tmp_sendmailmc
160 update_config "Addr=127.0.0.1," "" $tmp_sendmailmc
162 # copy to live configuration
163 cp -f $tmp_sendmailmc /etc/mail/sendmail.mc
164 rm -f $tmp_sendmailmc
166 # edit /etc/mail/access to add local IP
167 if ! grep "$PLC_RT_IP" /etc/mail/access ; then
168 echo "$PLC_RT_IP RELAY" >> /etc/mail/access
169 makemap hash /etc/mail/access.db < /etc/mail/access
171 if [ ! -f /etc/smrsh/rt-mailgate ] ; then
172 ln -s /usr/sbin/rt-mailgate /etc/smrsh/rt-mailgate
174 if ! grep "$PLC_RT_HOST" /etc/mail/local-host-names ; then
175 # edit /etc/mail/local-host-names
176 echo "$PLC_RT_HOST" >> /etc/mail/local-host-names
178 m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
179 service sendmail restart
185 if [ "$PLC_RT_ENABLED" != "1" ] ; then
191 MESSAGE=$"Bootstrap RT (please wait...)"
194 check_pg_hba $RT3_DB_NAME $RT3_DB_USER
195 #check_user_and_db $RT3_DB_NAME $RT3_DB_USER
198 if [ -n "$WROTE_PG_CONFIG" ] ; then
199 # NOTE: restart db to enable access by users granted above.
200 service plc restart postgresql
201 MESSAGE=$"Bootstrap RT 2 (please wait...)"
207 check_rt_custom # todo: restart httpd if needed.
214 MESSAGE=$"Deleting databases..."
217 service plc stop httpd
219 dropdb -U postgres $RT3_DB_NAME
220 dropuser -U postgres $RT3_DB_USER
221 rm -f /etc/rt3/RT_SiteConfig.pm
222 rm -f /etc/rt3/initialdata
223 PATTERN="host all postgres 127.0.0.1/32 trust"
224 sed -i -e "s|$PATTERN||g" $PGDATA/pg_hba.conf.d/${RT3_DB_NAME}.conf
226 sed -i -e "s/.*mailgate.*//g" /etc/aliases
227 rm -f /etc/rt3/setup.finished
229 sed -i -e "s/Port=smtp, Name=MTA/Port=smtp,Addr=127.0.0.1, Name=MTA/g" /etc/mail/sendmail.mc
230 service plc start httpd
236 MESSAGE=$"Stopping RT"
239 # TODO: is there anything to stop?