5 # Manage settings for the RT installtion
7 # Stephen Soltesz <soltesz@cs.princeton.edu>
8 # Copyright (C) 2008 The Trustees of Princeton University
13 # Source function library and configuration
14 . /etc/plc.d/functions
15 . /etc/planetlab/plc_config
16 local_config=/etc/planetlab/configs/site.xml
18 PLCRTPATH=/usr/share/plcrt
24 PGDATA=/var/lib/pgsql/data
25 postgresql_conf=$PGDATA/postgresql.conf
26 pghba_conf=$PGDATA/pg_hba.conf
28 # Export so that we do not have to specify -p to psql invocations
29 export PGPORT=$PLC_DB_PORT
37 if [ -z "$PLC_RT_IP" ] ; then
38 PLC_RT_IP=$( gethostbyname $PLC_RT_HOST )
41 # NOTE: code duplicated from monitor.functions to allow package to be separate
43 function check_pg_hba ()
47 #### SETUP ACCESS to this user and database
48 mkdir -p $PGDATA/pg_hba.conf.d
49 CONF=$PGDATA/pg_hba.conf.d/${NAME}.conf
50 if [ ! -f $CONF ] ; then
51 echo "host $NAME $USER 127.0.0.1/32 password" > $CONF
52 echo "host $NAME $USER $PLC_MONITOR_IP/32 password" >> $CONF
54 WROTE_PG_CONFIG="true"
58 # TODO: make values re-configurable... this may be an issue with RT's db, though.
59 function update_config ()
64 sed -i -e "s/$pattern/$with/g" $file
67 function check_rt_siteconfig ()
69 tmp_siteconfig=$(mktemp)
70 tmp_initialdata=$(mktemp)
72 # TODO: need a better approach for this.
73 for f in $PLCRTPATH/conf.d/*.pl ; do
74 update_config PLC_RT_HOSTNAME $PLC_RT_HOST $f
77 # if the templates are newer than the actual config, then replace them.
78 if [ $PLCRTPATH/RT_SiteConfig.pm -nt /etc/rt3/RT_SiteConfig.pm ] ;
81 cp -f $PLCRTPATH/RT_SiteConfig.pm $tmp_siteconfig
82 cp -f $PLCRTPATH/initialdata $tmp_initialdata
84 # setup RT_SiteConfig.pm
85 update_config PLC_NAME "$PLC_NAME" $tmp_siteconfig
86 update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_siteconfig
87 update_config PLC_WWW_HOSTNAME $PLC_WWW_HOST $tmp_siteconfig
89 update_config RT_DB_NAME $RT3_DB_NAME $tmp_siteconfig
90 update_config RT_DB_USER $RT3_DB_USER $tmp_siteconfig
91 update_config RT_DB_PASSWORD $PLC_MONITOR_DBPASSWORD $tmp_siteconfig
94 update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_initialdata
96 # copy to live configuration
97 cp -f $tmp_siteconfig /etc/rt3/RT_SiteConfig.pm
98 cp -f $tmp_initialdata /etc/rt3/initialdata
99 chmod 644 /etc/rt3/RT_SiteConfig.pm
100 chmod 644 /etc/rt3/initialdata
102 rm -f $tmp_siteconfig
103 rm -f $tmp_initialdata
107 function check_rt_custom ()
109 rsync -qv -az $PLCRTPATH/local/html /usr/share/rt3
112 function check_rt_pghba ()
116 CONF=$PGDATA/pg_hba.conf.d/${NAME}.conf
117 PATTERN="host all postgres 127.0.0.1/32 trust"
119 if ! grep -q "$PATTERN" $CONF ; then
120 #### SETUP ACCESS from postgres user to run init for the first time.
121 echo "$PATTERN" >> $CONF
122 WROTE_PG_CONFIG="true"
127 function check_rt_aliases ()
130 if ! grep -q "rt-mailgate --queue support" /etc/aliases ;
132 sed -i -e "s/^support.*postmaster//g" /etc/aliases
133 sed -i -e "s/^security.*root//g" /etc/aliases
134 cat <<EOF >> /etc/aliases
135 # added by RT init scripts for default queues.
136 support: "|/usr/sbin/rt-mailgate --queue support --action correspond --url http://localhost/rt3/"
137 monitor: "|/usr/sbin/rt-mailgate --queue monitor --action correspond --url http://localhost/rt3/"
138 security: "|/usr/sbin/rt-mailgate --queue security --action correspond --url http://localhost/rt3/"
139 legal: "|/usr/sbin/rt-mailgate --queue legal --action correspond --url http://localhost/rt3/"
146 function check_rt_init ()
148 if [ ! -f /etc/rt3/setup.finished ] ; then
149 /usr/sbin/rt-setup-database --action init --dba postgres
150 for f in $PLCRTPATH/conf.d/*.pl ; do
151 /usr/sbin/rt-setup-database --action insert --dba postgres --datafile $f
154 # run initial setup scripts (run only once, or for the first time)
155 if [ -d $PLCRTPATH/setup.d ] ; then
156 for f in $PLCRTPATH/setup.d/*.{pl,py,sh} ; do
161 touch /etc/rt3/setup.finished
168 tmp_sendmailmc=$(mktemp)
170 # if the templates is newer than the processed config, then update it
171 if grep -q "Addr=127.0.0.1," /etc/mail/sendmail.mc ;
174 cp -f /etc/mail/sendmail.mc $tmp_sendmailmc
177 update_config "Addr=127.0.0.1," "" $tmp_sendmailmc
179 # copy to live configuration
180 cp -f $tmp_sendmailmc /etc/mail/sendmail.mc
181 rm -f $tmp_sendmailmc
183 # edit /etc/mail/access to add local IP
184 if ! grep "$PLC_RT_IP" /etc/mail/access ; then
185 echo "$PLC_RT_IP RELAY" >> /etc/mail/access
186 makemap hash /etc/mail/access.db < /etc/mail/access
188 if [ ! -f /etc/smrsh/rt-mailgate ] ; then
189 ln -s /usr/sbin/rt-mailgate /etc/smrsh/rt-mailgate
191 if ! grep "$PLC_RT_HOST" /etc/mail/local-host-names ; then
192 # edit /etc/mail/local-host-names
193 echo "$PLC_RT_HOST" >> /etc/mail/local-host-names
195 m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
196 service sendmail restart
202 if [ "$PLC_RT_ENABLED" != "1" ] ; then
208 MESSAGE=$"Bootstrap RT (please wait...)"
211 check_pg_hba $RT3_DB_NAME $RT3_DB_USER
212 #check_user_and_db $RT3_DB_NAME $RT3_DB_USER
215 if [ -n "$WROTE_PG_CONFIG" ] ; then
216 # NOTE: restart db to enable access by users granted above.
217 service plc restart postgresql
218 MESSAGE=$"Bootstrap RT 2 (please wait...)"
224 check_rt_custom # todo: restart httpd if needed.
231 MESSAGE=$"Deleting databases..."
234 service plc stop httpd
236 dropdb -U postgres $RT3_DB_NAME
237 dropuser -U postgres $RT3_DB_USER
238 rm -f /etc/rt3/RT_SiteConfig.pm
239 rm -f /etc/rt3/initialdata
240 PATTERN="host all postgres 127.0.0.1/32 trust"
241 sed -i -e "s|$PATTERN||g" $PGDATA/pg_hba.conf.d/${RT3_DB_NAME}.conf
243 sed -i -e "s/.*mailgate.*//g" /etc/aliases
244 rm -f /etc/rt3/setup.finished
246 sed -i -e "s/Port=smtp, Name=MTA/Port=smtp,Addr=127.0.0.1, Name=MTA/g" /etc/mail/sendmail.mc
247 service plc start httpd
253 MESSAGE=$"Stopping RT"
256 # TODO: is there anything to stop?