+function start_tg_server ()
+{
+ stop_tg_server
+ pushd ${MONITORPATH}/web/MonitorWeb/
+ mkdir -p /var/log/monitor/monitorweb/
+ cp /var/log/monitorweb.log /var/lib/monitor/monitorweb/`date +%Y-%m-%d-%H-%M`-monitorweb.log
+ ./start-monitorweb.py ${MONITORPATH}/web/MonitorWeb/prod.cfg &> /var/log/monitorweb.log &
+ popd
+}
+
+function stop_tg_server ()
+{
+ pid=$( cat /var/run/monitorweb.pid )
+ if [ -n "$pid" ] ; then
+ kill $pid
+ fi
+}
+
+if [ "$PLC_MONITOR_ENABLED" != "1" ] ; then
+ exit 0
+fi
+
+case "$1" in
+ start)
+ MESSAGE=$"Bootstrap Monitoring (please wait...)"
+ dialog "$MESSAGE"
+
+ # DATABASE acces, creation, and data loading
+ check_pg_hba $MONITOR_DB_NAME $MONITOR_DB_USER
+ check_user_and_db $MONITOR_DB_NAME $MONITOR_DB_USER
+ # WRITE default /etc/monitor.conf
+ check_monitor_conf
+
+ check_gadget_config
+
+ if [ -n "$WROTE_PG_CONFIG" ] ; then
+ # NOTE: restart db to enable access by users granted above.
+ service plc restart postgresql
+ service plc restart httpd
+ MESSAGE=$"Bootstrap Monitoring 2 (please wait...)"
+ dialog "$MESSAGE"
+ fi
+
+ check_monitor_schema_and_data_init
+
+ # create /etc/httpd/conf.d/monitorweb.conf
+ create_httpd_conf
+ if [ -n "$WROTE_HTTP_CONFIG" ] ; then
+ # NOTE: restart web server to enable access web cfg
+ service plc restart httpd
+ MESSAGE=$"Bootstrap Monitoring 3 (please wait...)"
+ dialog "$MESSAGE"
+ fi
+ start_tg_server
+
+ result "$MESSAGE"
+ ;;
+
+ restartweb)
+ MESSAGE=$"Restarting monitor web app..."
+ dialog "$MESSAGE"
+
+ stop_tg_server
+ start_tg_server
+
+ result "$MESSAGE"