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/planetlab/plc_config
17 local_config=/etc/planetlab/configs/site.xml
19 MONITORPATH=/usr/share/monitor
25 PGDATA=/var/lib/pgsql/data
26 postgresql_conf=$PGDATA/postgresql.conf
27 pghba_conf=$PGDATA/pg_hba.conf
29 # Export so that we do not have to specify -p to psql invocations
30 export PGPORT=$PLC_DB_PORT
33 MONITOR_DB_USER="monitoruser"
34 MONITOR_DB_NAME="monitor"
38 if [ -z "$PLC_MONITOR_IP" ] ; then
39 PLC_MONITOR_IP=$( gethostbyname $PLC_MONITOR_HOST )
42 function check_monitor_schema_and_data()
44 # NOTE: call create_all() to setup the database from the info model.
45 python -c "from monitor.database.info.model import *; from elixir import create_all; create_all()"
48 function check_monitor_conf ()
50 MONITOR_CONFIG=/etc/monitor.conf
52 # Using plcsh add default, monitor user
53 plcsh <<EOF &>/dev/null
54 AddPerson({'first_name' : 'Monitor', 'last_name' : 'Server', 'password' : '${PLC_MONITOR_DBPASSWORD}', 'email' : '${PLC_MONITOR_EMAIL}'})
55 AddRoleToPerson('admin', '${PLC_MONITOR_EMAIL}')
56 AddPersonToSite('${PLC_MONITOR_EMAIL}', '${PLC_SLICE_PREFIX}')
57 UpdatePerson('${PLC_MONITOR_EMAIL}', { 'enabled' : True, 'password' : '${PLC_MONITOR_DBPASSWORD}' })
60 if [ ! -f ${MONITOR_CONFIG} ] ; then
61 cat <<EOF > ${MONITOR_CONFIG}
63 RT_DB_HOST=rt.planet-lab.org
69 RT_WEB_SERVER=https://rt.planet-lab.org/
77 API_SERVER=https://${PLC_BOOT_HOST}/PLCAPI/
78 API_AUTH_USER=${PLC_MONITOR_EMAIL}
79 API_AUTH_PASSWORD=${PLC_MONITOR_DBPASSWORD}
82 MONITOR_SCRIPT_ROOT=${MONITORPATH}
83 MONITOR_DATA_ROOT=/var/lib/monitor
84 MONITOR_ARCHIVE_ROOT=/var/lib/monitor/archive-pdb
85 MONITOR_BOOTMANAGER_LOG=/var/www/html/monitorlog
87 MONITOR_HOSTNAME=${PLC_MONITOR_HOST}
88 MONITOR_IP=${PLC_MONITOR_IP}
90 PLC_WWW_HOSTNAME=${PLC_WWW_HOST}
96 # all messages will appear to be from this address
97 from_email=${PLC_MONITOR_EMAIL}
99 # a separate address for support messages
100 support_email=${PLC_MAIL_SUPPORT_ADDRESS}
102 # mailing list copied on all out-going messages
106 monitor_dburi=postgres://${MONITOR_DB_USER}:${PLC_MONITOR_DBPASSWORD}@localhost:5432/${MONITOR_DB_NAME}
107 zabbix_dburi=postgres://${ZABBIX_DB_USER}:${PLC_MONITOR_DBPASSWORD}@localhost:5432/${ZABBIX_DB_NAME}
111 # Evaluated as true or false
129 function create_httpd_conf ()
131 MONITOR_HTTP_CONF=/etc/httpd/conf.d/monitorweb.conf
133 if [ ! -f ${MONITOR_HTTP_CONF} ] ; then
134 # note: we need to either start this script before httpd, or always
135 # restart httpd, since there's no way to know beyond file's existence
136 # whether the values have changed or not.
137 WROTE_HTTP_CONFIG="true"
140 # TODO: support HTTPS as well as port 80. currently not specifying port
141 # 80 breaks https for other content on the myplc.
142 # TODO: make proxy port configurable.
144 cat <<EOF > ${MONITOR_HTTP_CONF}
146 # NOTE: I've tried other means of redirection, including mod_rewrite, but did
147 # not have any success. The means below is not idea, b/c it does not keep
148 # non-ssl session as non-ssl. But it works.
150 # NOTE: redirect path without trailing '/' to path with. Favor SSL.
151 Redirect /monitor https://${PLC_MONITOR_HOST}:${PLC_WWW_SSL_PORT}/monitor/
153 # NOTE: this directive strips '/monitor/' from the requested path and pastes
154 # the remaining part to the end of the ProxyPass url below. All TG urls
155 # should be relative to their current position, or the absolute path
156 # that includes /monitor/ at the beginning.
157 # TODO: make location configurable.
158 <Location '/monitor/'>
160 #Errorlog /var/log/httpd/monitorwebapp-error_log
161 #Customlog /var/log/httpd/monitorwebapp-access_log common
163 ProxyPass http://127.0.0.1:8082/
164 ProxyPassReverse http://127.0.0.1:8082/
170 function start_tg_server ()
173 pushd ${MONITORPATH}/web/MonitorWeb/
174 ./start-monitorweb.py ${MONITORPATH}/web/MonitorWeb/prod.cfg &> /var/log/monitorweb.log &
178 function stop_tg_server ()
180 pid=$( cat /var/run/monitorweb.pid )
181 if [ -n "$pid" ] ; then
186 if [ "$PLC_MONITOR_ENABLED" != "1" ] ; then
192 MESSAGE=$"Bootstrap Monitoring (please wait...)"
195 # DATABASE acces, creation, and data loading
196 check_pg_hba $MONITOR_DB_NAME $MONITOR_DB_USER
197 check_user_and_db $MONITOR_DB_NAME $MONITOR_DB_USER
198 # WRITE default /etc/monitor.conf
201 if [ -n "$WROTE_PG_CONFIG" ] ; then
202 # NOTE: restart db to enable access by users granted above.
203 service plc restart postgresql
204 service plc restart httpd
205 MESSAGE=$"Bootstrap Monitoring 2 (please wait...)"
209 check_monitor_schema_and_data
211 # create /etc/httpd/conf.d/monitorweb.conf
213 if [ -n "$WROTE_HTTP_CONFIG" ] ; then
214 # NOTE: restart web server to enable access web cfg
215 service plc restart httpd
216 MESSAGE=$"Bootstrap Monitoring 3 (please wait...)"
225 MESSAGE=$"Restarting monitor web app..."
235 MESSAGE=$"Deleting databases..."
238 dropdb -U postgres $MONITOR_DB_NAME
239 dropuser -U postgres $MONITOR_DB_USER
245 MESSAGE=$"Stopping Monitor"
249 # todo: disable cron entry?