+function create_httpd_conf ()
+{
+ MONITOR_HTTP_CONF=/etc/httpd/conf.d/monitorweb.conf
+
+ if [ ! -f ${MONITOR_HTTP_CONF} ] ; then
+ # note: we need to either start this script before httpd, or always
+ # restart httpd, since there's no way to know beyond file's existence
+ # whether the values have changed or not.
+ WROTE_HTTP_CONFIG="true"
+ fi
+
+ # TODO: support HTTPS as well as port 80. currently not specifying port
+ # 80 breaks https for other content on the myplc.
+ # TODO: make proxy port configurable.
+
+ cat <<EOF > ${MONITOR_HTTP_CONF}
+
+# NOTE: I've tried other means of redirection, including mod_rewrite, but did
+# not have any success. The means below is not idea, b/c it does not keep
+# non-ssl session as non-ssl. But it works.
+
+# NOTE: redirect path without trailing '/' to path with. Favor SSL.
+Redirect /monitor https://${PLC_MONITOR_HOST}:${PLC_WWW_SSL_PORT}/monitor/
+
+# NOTE: this directive strips '/monitor/' from the requested path and pastes
+# the remaining part to the end of the ProxyPass url below. All TG urls
+# should be relative to their current position, or the absolute path
+# that includes /monitor/ at the beginning.
+# TODO: make location configurable.
+<Location '/monitor/'>
+ #LogLevel debug
+ #Errorlog /var/log/httpd/monitorwebapp-error_log
+ #Customlog /var/log/httpd/monitorwebapp-access_log common
+
+ ProxyPass http://127.0.0.1:8082/
+ ProxyPassReverse http://127.0.0.1:8082/
+</Location>
+
+EOF
+}
+
+function start_tg_server ()
+{
+ stop_tg_server
+ pushd ${MONITORPATH}/web/MonitorWeb/
+ ./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
+}
+