Charm: ~nijaba:oneiric/limesurvey
Revision: 13
Hook: db-relation-changed
#!/bin/bash
set -eu # -x for verbose logging to juju debug-log
FORMULA_DIR=$(dirname $0)
if [[ -e $FORMULA_DIR/limesurvey-common ]] ; then
. $FORMULA_DIR/limesurvey-common
else
juju-log "ERROR: Could not load limesurvey-common from $FORMULA_DIR"
echo "ERROR: Could not load limesurvey-common from $FORMULA_DIR"
exit 1
fi
juju-log "Creating appropriate upload paths and directories"
# Setup appropriate upload paths and directories
ln -sf $LPATH "/var/www/$hostname"
chmod 755 -R $LPATH
chown -R root:www-data $LPATH/tmp
chown -R root:www-data $LPATH/upload
chmod 0770 -R "$LPATH/tmp"
chmod 0770 -R "$LPATH/upload"
# write the invariant part of the config file
set-invariant-config
# Write the limesurvey config
set-config
juju-log "Starting limesurvey install"
pushd /var/opt/limesurvey
# move admin back for just this
if [ -d /var/lib/juju/limesurvey.install ] && [ ! -d admin/install ] ; then
mv /var/lib/juju/limesurvey.admin admin/install
fi
php5 admin/install/cmd_install.php install
# move install out of webroot
mv admin/install /var/lib/juju/limesurvey.install
popd
# Write the apache config
# XXX a future branch will change this to use augtool
apache_config_file_path="/etc/apache2/sites-available/$hostname"
juju-log "Writing apache config file $apache_config_file_path"
cat > $apache_config_file_path <<EOF
<VirtualHost *:80>
ServerName $hostname
DocumentRoot /var/www/$hostname
Options All
ErrorLog /var/log/apache2/ls-error.log
TransferLog /var/log/apache2/ls-access.log
</VirtualHost>
EOF
chmod 0644 $apache_config_file_path
# Configure apache
juju-log "Enabling apache modules: rewrite, vhost_alias"
a2enmod rewrite
a2enmod vhost_alias
juju-log "Enabling apache site: $hostname"
a2ensite $hostname
#disable default site so that resolution is dependable with load balancing
a2dissite default
# Restart apache
juju-log "Restarting apache2 service"
/etc/init.d/apache2 restart
# Make it publicly visible, once the wordpress service is exposed
open-port 80/tcp