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
77 function apply_template ()
83 cp $TEMPLATE $tmp_file
84 update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_file
85 update_config PLC_RT_CC_ADDRESS $PLC_RT_CC_ADDRESS $tmp_file
87 update_config PLC_NAME "$PLC_NAME" $tmp_file
88 update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_file
89 update_config PLC_WWW_HOSTNAME $PLC_WWW_HOST $tmp_file
91 update_config RT_DB_NAME $RT3_DB_NAME $tmp_file
92 update_config RT_DB_USER $RT3_DB_USER $tmp_file
93 update_config RT_DB_PASSWORD $PLC_RT_DBPASSWORD $tmp_file
96 update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_file
98 cp $tmp_file $DESTFILE
102 function check_rt_templates ()
104 for f in $PLCRTPATH/conf.d/*.pl ; do
105 mkdir -p /etc/rt3/conf.d
106 if [ $f -nt /etc/rt3/conf.d/`basename $f` ] ; then
107 apply_template $f /etc/rt3/conf.d/`basename $f`
111 for f in $PLCRTPATH/setup.d/*.{pl,py,sh} ; do
112 mkdir -p /etc/rt3/setup.d
113 if [ $f -nt /etc/rt3/setup.d/`basename $f` ] ; then
114 apply_template $f /etc/rt3/setup.d/`basename $f`
115 chmod 751 /etc/rt3/setup.d/`basename $f`
119 # TODO: need a better approach for this.
120 if [ -f /etc/httpd/conf.d/rt3.conf ] ; then
121 update_config PLC_RT_HOST $PLC_RT_HOST /etc/httpd/conf.d/rt3.conf
124 # if the templates are newer than the actual config, then replace them.
125 if [ $PLCRTPATH/RT_SiteConfig.pm -nt /etc/rt3/RT_SiteConfig.pm ] ;
128 apply_template $PLCRTPATH/RT_SiteConfig.pm /etc/rt3/RT_SiteConfig.pm
129 apply_template $PLCRTPATH/initialdata /etc/rt3/initialdata
130 chmod 644 /etc/rt3/RT_SiteConfig.pm
131 chmod 644 /etc/rt3/initialdata
135 function check_rt_custom ()
137 rsync -qv -az $PLCRTPATH/local/html /usr/share/rt3
140 function check_rt_pghba ()
144 CONF=$PGDATA/pg_hba.conf.d/${NAME}.conf
145 PATTERN="host all postgres 127.0.0.1/32 trust"
146 if ! grep -q "$PATTERN" $CONF ; then
147 #### SETUP ACCESS from postgres user to run init for the first time.
148 echo "$PATTERN" >> $CONF
149 WROTE_PG_CONFIG="true"
152 PATTERN="host all postgres $PLC_RT_IP/32 trust"
153 if ! grep -q "$PATTERN" $CONF ; then
154 #### SETUP ACCESS from postgres user to run init for the first time.
155 echo "$PATTERN" >> $CONF
156 WROTE_PG_CONFIG="true"
161 function check_rt_aliases ()
164 if ! grep -q "rt-mailgate --queue support" /etc/aliases ;
166 sed -i -e "s/^support.*postmaster//g" /etc/aliases
167 sed -i -e "s/^security.*root//g" /etc/aliases
168 cat <<EOF >> /etc/aliases
169 # added by RT init scripts for default queues.
170 support: "|/usr/sbin/rt-mailgate --queue support --action correspond --url http://$PLC_RT_HOST/rt3/"
171 monitor: "|/usr/sbin/rt-mailgate --queue monitor --action correspond --url http://$PLC_RT_HOST/rt3/"
172 security: "|/usr/sbin/rt-mailgate --queue security --action correspond --url http://$PLC_RT_HOST/rt3/"
173 legal: "|/usr/sbin/rt-mailgate --queue legal --action correspond --url http://$PLC_RT_HOST/rt3/"
180 function check_rt_init ()
182 if [ ! -f /etc/rt3/setup.finished ] ; then
183 /usr/sbin/rt-setup-database --action init --dba postgres
185 for f in /etc/rt3/conf.d/*.pl ; do
186 /usr/sbin/rt-setup-database --action insert --dba postgres --datafile $f
189 # run initial setup scripts (run only once, or for the first time)
190 if [ -d /etc/rt3/setup.d ] ; then
191 for f in /etc/rt3/setup.d/*.{pl,py,sh} ; do
198 touch /etc/rt3/setup.finished
205 tmp_sendmailmc=$(mktemp)
207 # if the templates is newer than the processed config, then update it
208 if grep -q "Addr=127.0.0.1," /etc/mail/sendmail.mc ;
211 cp -f /etc/mail/sendmail.mc $tmp_sendmailmc
214 update_config "Addr=127.0.0.1," "" $tmp_sendmailmc
216 # copy to live configuration
217 cp -f $tmp_sendmailmc /etc/mail/sendmail.mc
218 rm -f $tmp_sendmailmc
220 # edit /etc/mail/access to add local IP
221 if ! grep "$PLC_RT_IP" /etc/mail/access ; then
222 echo "$PLC_RT_IP RELAY" >> /etc/mail/access
223 makemap hash /etc/mail/access.db < /etc/mail/access
225 if [ ! -f /etc/smrsh/rt-mailgate ] ; then
226 ln -s /usr/sbin/rt-mailgate /etc/smrsh/rt-mailgate
228 if ! grep "$PLC_RT_HOST" /etc/mail/local-host-names ; then
229 # edit /etc/mail/local-host-names
230 echo "$PLC_RT_HOST" >> /etc/mail/local-host-names
232 m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
233 service sendmail restart
239 if [ "$PLC_RT_ENABLED" != "1" ] ; then
245 MESSAGE=$"Bootstrap RT (please wait...)"
249 check_pg_hba $RT3_DB_NAME $RT3_DB_USER
250 #check_user_and_db $RT3_DB_NAME $RT3_DB_USER
252 # TODO: make this dependent on whether a change was made!
253 service plc restart httpd
256 if [ -n "$WROTE_PG_CONFIG" ] ; then
257 # NOTE: restart db to enable access by users granted above.
258 service plc restart postgresql
259 MESSAGE=$"Bootstrap RT 2 (please wait...)"
265 check_rt_custom # todo: restart httpd if needed.
267 # NOTE: remove external permission
268 # This is needed to allow it to run without localhost
269 # TODO: find a better way to do this.
271 # remove 'trust' entry from .conf file
272 sed -i -e "s/.*trust//g" $PGDATA/pg_hba.conf.d/${RT3_DB_NAME}.conf
273 if [ -n "$WROTE_PG_CONFIG" ] ; then
274 # NOTE: restart db to enable access by users granted above.
275 service plc restart postgresql
276 MESSAGE=$"Bootstrap RT 3 (please wait...)"
285 MESSAGE=$"Deleting databases..."
288 service plc stop httpd
290 dropdb -U postgres $RT3_DB_NAME
291 dropuser -U postgres $RT3_DB_USER
292 rm -f /etc/rt3/RT_SiteConfig.pm
293 rm -f /etc/rt3/initialdata
294 rm -f /etc/rt3/conf.d/*.pl
295 rm -f $PGDATA/pg_hba.conf.d/${RT3_DB_NAME}.conf
297 sed -i -e "s/.*mailgate.*//g" /etc/aliases
298 rm -f /etc/rt3/setup.finished
300 sed -i -e "s/Port=smtp, Name=MTA/Port=smtp,Addr=127.0.0.1, Name=MTA/g" /etc/mail/sendmail.mc
301 service plc start httpd
307 MESSAGE=$"Stopping RT"
310 # TODO: is there anything to stop?