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 function check_rt_password ()
43 if [[ -z "$PLC_RT_DBPASSWORD" || "$PLC_RT_DBPASSWORD" = "None" ]] ; then
44 # NOTE: this provides a simpler string than uuidgen
45 PLC_RT_DBPASSWORD=$( uuidgen | md5sum - | awk '{print $1}' )
46 plc-config --category=plc_rt --variable=dbpassword --value="$PLC_RT_DBPASSWORD" --save=$local_config $local_config
52 # NOTE: code duplicated from monitor.functions to allow package to be separate
54 function check_pg_hba ()
58 #### SETUP ACCESS to this user and database
59 mkdir -p $PGDATA/pg_hba.conf.d
60 CONF=$PGDATA/pg_hba.conf.d/${NAME}.conf
61 if [ ! -f $CONF ] ; then
62 echo "host $NAME $USER 127.0.0.1/32 password" > $CONF
63 echo "host $NAME $USER $PLC_RT_IP/32 password" >> $CONF
65 WROTE_PG_CONFIG="true"
69 # TODO: make values re-configurable... this may be an issue with RT's db, though.
70 function update_config ()
75 sed -i -e "s/$pattern/$with/g" $file
78 function check_rt_siteconfig ()
80 tmp_siteconfig=$(mktemp)
81 tmp_initialdata=$(mktemp)
83 # TODO: need a better approach for this.
84 for f in $PLCRTPATH/conf.d/*.pl ; do
85 mkdir -p /etc/rt3/conf.d
86 if [ $f -nt /etc/rt3/conf.d/`basename $f` ] ; then
89 update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_file
91 cp $tmp_file /etc/rt3/conf.d/`basename $f`
96 # TODO: need a better approach for this.
97 if [ -f /etc/httpd/conf.d/rt3.conf ] ; then
98 update_config PLC_RT_HOST $PLC_RT_HOST /etc/httpd/conf.d/rt3.conf
101 # if the templates are newer than the actual config, then replace them.
102 if [ $PLCRTPATH/RT_SiteConfig.pm -nt /etc/rt3/RT_SiteConfig.pm ] ;
105 cp -f $PLCRTPATH/RT_SiteConfig.pm $tmp_siteconfig
106 cp -f $PLCRTPATH/initialdata $tmp_initialdata
108 # setup RT_SiteConfig.pm
109 update_config PLC_NAME "$PLC_NAME" $tmp_siteconfig
110 update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_siteconfig
111 update_config PLC_WWW_HOSTNAME $PLC_WWW_HOST $tmp_siteconfig
113 update_config RT_DB_NAME $RT3_DB_NAME $tmp_siteconfig
114 update_config RT_DB_USER $RT3_DB_USER $tmp_siteconfig
115 update_config RT_DB_PASSWORD $PLC_RT_DBPASSWORD $tmp_siteconfig
118 update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_initialdata
120 # copy to live configuration
121 cp -f $tmp_siteconfig /etc/rt3/RT_SiteConfig.pm
122 cp -f $tmp_initialdata /etc/rt3/initialdata
123 chmod 644 /etc/rt3/RT_SiteConfig.pm
124 chmod 644 /etc/rt3/initialdata
126 rm -f $tmp_siteconfig
127 rm -f $tmp_initialdata
131 function check_rt_custom ()
133 rsync -qv -az $PLCRTPATH/local/html /usr/share/rt3
136 function check_rt_pghba ()
140 CONF=$PGDATA/pg_hba.conf.d/${NAME}.conf
141 PATTERN="host all postgres 127.0.0.1/32 trust"
142 if ! grep -q "$PATTERN" $CONF ; then
143 #### SETUP ACCESS from postgres user to run init for the first time.
144 echo "$PATTERN" >> $CONF
145 WROTE_PG_CONFIG="true"
148 PATTERN="host all postgres $PLC_RT_IP/32 trust"
149 if ! grep -q "$PATTERN" $CONF ; then
150 #### SETUP ACCESS from postgres user to run init for the first time.
151 echo "$PATTERN" >> $CONF
152 WROTE_PG_CONFIG="true"
157 function check_rt_aliases ()
160 if ! grep -q "rt-mailgate --queue support" /etc/aliases ;
162 sed -i -e "s/^support.*postmaster//g" /etc/aliases
163 sed -i -e "s/^security.*root//g" /etc/aliases
164 cat <<EOF >> /etc/aliases
165 # added by RT init scripts for default queues.
166 support: "|/usr/sbin/rt-mailgate --queue support --action correspond --url http://localhost/rt3/"
167 monitor: "|/usr/sbin/rt-mailgate --queue monitor --action correspond --url http://localhost/rt3/"
168 security: "|/usr/sbin/rt-mailgate --queue security --action correspond --url http://localhost/rt3/"
169 legal: "|/usr/sbin/rt-mailgate --queue legal --action correspond --url http://localhost/rt3/"
176 function check_rt_init ()
178 if [ ! -f /etc/rt3/setup.finished ] ; then
179 /usr/sbin/rt-setup-database --action init --dba postgres
180 for f in /etc/rt3/conf.d/*.pl ; do
181 /usr/sbin/rt-setup-database --action insert --dba postgres --datafile $f
184 # run initial setup scripts (run only once, or for the first time)
185 if [ -d $PLCRTPATH/setup.d ] ; then
186 for f in $PLCRTPATH/setup.d/*.{pl,py,sh} ; do
191 touch /etc/rt3/setup.finished
198 tmp_sendmailmc=$(mktemp)
200 # if the templates is newer than the processed config, then update it
201 if grep -q "Addr=127.0.0.1," /etc/mail/sendmail.mc ;
204 cp -f /etc/mail/sendmail.mc $tmp_sendmailmc
207 update_config "Addr=127.0.0.1," "" $tmp_sendmailmc
209 # copy to live configuration
210 cp -f $tmp_sendmailmc /etc/mail/sendmail.mc
211 rm -f $tmp_sendmailmc
213 # edit /etc/mail/access to add local IP
214 if ! grep "$PLC_RT_IP" /etc/mail/access ; then
215 echo "$PLC_RT_IP RELAY" >> /etc/mail/access
216 makemap hash /etc/mail/access.db < /etc/mail/access
218 if [ ! -f /etc/smrsh/rt-mailgate ] ; then
219 ln -s /usr/sbin/rt-mailgate /etc/smrsh/rt-mailgate
221 if ! grep "$PLC_RT_HOST" /etc/mail/local-host-names ; then
222 # edit /etc/mail/local-host-names
223 echo "$PLC_RT_HOST" >> /etc/mail/local-host-names
225 m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
226 service sendmail restart
232 if [ "$PLC_RT_ENABLED" != "1" ] ; then
238 MESSAGE=$"Bootstrap RT (please wait...)"
242 check_pg_hba $RT3_DB_NAME $RT3_DB_USER
243 #check_user_and_db $RT3_DB_NAME $RT3_DB_USER
245 # TODO: make this dependent on whether a change was made!
246 service plc restart httpd
249 if [ -n "$WROTE_PG_CONFIG" ] ; then
250 # NOTE: restart db to enable access by users granted above.
251 service plc restart postgresql
252 MESSAGE=$"Bootstrap RT 2 (please wait...)"
258 check_rt_custom # todo: restart httpd if needed.
260 # NOTE: remove external permission
261 # This is needed to allow it to run without localhost
262 # TODO: find a better way to do this.
264 # remove 'trust' entry from .conf file
265 sed -i -e "s/.*trust//g" $PGDATA/pg_hba.conf.d/${RT3_DB_NAME}.conf
266 if [ -n "$WROTE_PG_CONFIG" ] ; then
267 # NOTE: restart db to enable access by users granted above.
268 service plc restart postgresql
269 MESSAGE=$"Bootstrap RT 3 (please wait...)"
278 MESSAGE=$"Deleting databases..."
281 service plc stop httpd
283 dropdb -U postgres $RT3_DB_NAME
284 dropuser -U postgres $RT3_DB_USER
285 rm -f /etc/rt3/RT_SiteConfig.pm
286 rm -f /etc/rt3/initialdata
287 rm -f /etc/rt3/conf.d/*.pl
288 rm -f $PGDATA/pg_hba.conf.d/${RT3_DB_NAME}.conf
290 sed -i -e "s/.*mailgate.*//g" /etc/aliases
291 rm -f /etc/rt3/setup.finished
293 sed -i -e "s/Port=smtp, Name=MTA/Port=smtp,Addr=127.0.0.1, Name=MTA/g" /etc/mail/sendmail.mc
294 service plc start httpd
300 MESSAGE=$"Stopping RT"
303 # TODO: is there anything to stop?