From 7aec2bd4c9f7669612651b90231f5662dd2d8a85 Mon Sep 17 00:00:00 2001 From: attardi <giuseppe.attardi@garr.it> Date: Fri, 28 Jun 2019 06:32:11 +0000 Subject: [PATCH] chown www-data --- hooks/install | 73 ++++++++++++++++++++++++++++++++------------------- hooks/start | 1 + metadata.yaml | 8 +++--- 3 files changed, 51 insertions(+), 31 deletions(-) diff --git a/hooks/install b/hooks/install index 5fd0349..21d7fd1 100755 --- a/hooks/install +++ b/hooks/install @@ -4,51 +4,70 @@ set -e juju-log "Running drupal install." PHP_VER=7.0 +APPLICATION_NAME=drupal +DOCROOT=/var/www/$APPLICATION_NAME apt -qqy update && apt -qqy dist-upgrade apt -y install drush apache2 php${PHP_VER}-gd libapache2-mod-php${PHP_VER} \ - php${PHP_VER}-cgi mysql-client-core-5.7 php${PHP_VER}-json php$(PHP_VER}-xml + php${PHP_VER}-cgi mysql-client-core-5.7 php${PHP_VER}-json php${PHP_VER}-xml -a2enmod php$(PHP_VER) - -service apache2 restart +a2enmod php${PHP_VER} mv -f /etc/php/${PHP_VER}/cli/php.ini /etc/php/${PHP_VER}/cli/php.ini.bak cat /etc/php/${PHP_VER}/cli/php.ini.bak | sed -e 's/^disable_functions.*$/disable_functions = /g' > /etc/php/${PHP_VER}/cli/php.ini +# Download drupal if not already downloaded. cd /var/www -#Download drupal if not already downloaded. [ -d /var/www/drupal ] || drush dl drupal-7 -[ -d /var/www/drupal ] || mv drupal-7.* drupal +[ -d /var/www/drupal ] || mv drupal-7.* $DOCROOT +chown -R www-data:www-data $DOCROOT/sites/default + +# Create Drupal HTTP site configuration + +cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/$APPLICATION_NAME.conf +sed -i "s|DocumentRoot /var/www/html|DocumentRoot $DOCROOT|g" /etc/apache2/sites-available/$APPLICATION_NAME.conf +sed -i "s|ErrorLog \${APACHE_LOG_DIR}/error.log|ErrorLog \${APACHE_LOG_DIR}/error-$APPLICATION_NAME-http.log|g" /etc/apache2/sites-available/$APPLICATION_NAME.conf +sed -i "s|CustomLog \${APACHE_LOG_DIR}/access.log combined|CustomLog \${APACHE_LOG_DIR}/access-$APPLICATION_NAME-http.log combined|g" /etc/apache2/sites-available/$APPLICATION_NAME.conf + +a2dissite 000-default +# Enable Drupal HTTP site configuration +a2ensite $APPLICATION_NAME -#Disable default website if still enabled -[ -f /etc/apache2/sites-enabled/000-default ] && a2dissite 000-default +# Enable module SSL +if [ ! -e /etc/apache2/mods-available/ssl.conf.bak ]; then + # save a backup of the original file, just in case... + cp /etc/apache2/mods-available/ssl.conf /etc/apache2/mods-available/ssl.conf.bak +fi +a2enmod ssl + +# Create Drupal HTTPS site configuration +cp /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-available/$APPLICATION_NAME-ssl.conf +sed -i "s|DocumentRoot /var/www/html|DocumentRoot $DOCROOT|g" /etc/apache2/sites-available/$APPLICATION_NAME-ssl.conf +sed -i "s|ErrorLog \${APACHE_LOG_DIR}/error.log|ErrorLog \${APACHE_LOG_DIR}/error-$APPLICATION_NAME-https.log|g" /etc/apache2/sites-available/$APPLICATION_NAME-ssl.conf +sed -i "s|CustomLog \${APACHE_LOG_DIR}/access.log combined|CustomLog \${APACHE_LOG_DIR}/access-$APPLICATION_NAME-https.log combined|g" /etc/apache2/sites-available/$APPLICATION_NAME-ssl.conf -if [ ! -f /etc/apache2/sites-enabled/drupal ]; then - juju-log "Creating apache2 configuration" - cat <<EOF > /etc/apache2/sites-available/drupal +# Configure HTTP redirect to HTTPS +a2enmod rewrite +cat <<EOF +EOF > /etc/apache2/conf-available/https-rewrite.conf <VirtualHost *:80> - ServerAdmin webmaster@localhost - DocumentRoot /var/www/drupal - - <Directory /var/www/drupal> - Options Indexes FollowSymLinks MultiViews - AllowOverride All - Order allow,deny - allow from all - </Directory> - - ErrorLog \${APACHE_LOG_DIR}/error.log - LogLevel warn - - CustomLog \${APACHE_LOG_DIR}/access.log combined +RewriteEngine On +RewriteCond %{HTTPS} off +RewriteRule (.*) https://%{HTTP_HOST}:443%{REQUEST_URI} </VirtualHost> EOF - a2ensite drupal + +# Prevent the sudo message "unable to resolve..." +MYNAME=`hostname` +if [ `grep $MYNAME /etc/hosts > /dev/null` ]; then + echo "127.0.1.1 $MYNAME" >> /etc/hosts fi -service apache2 reload +service apache2 restart +open-port 80 + +status-set maintenance "Installed" exit 0 diff --git a/hooks/start b/hooks/start index be03e68..c451a81 100755 --- a/hooks/start +++ b/hooks/start @@ -2,3 +2,4 @@ set -e juju-log "Starting apache." service apache2 start +status-set active "Ready" diff --git a/metadata.yaml b/metadata.yaml index 3c36baf..ffddbbc 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -1,12 +1,12 @@ -name: drupal +name: drupal7 series: - xenial - bionic summary: "Drupal CMS" -maintainer: "Giuseppe Attardi.giuseppe.attardi@garr.it>" +maintainer: "Giuseppe Attardi <giuseppe.attardi@garr.it>" description: | - Installs the drupal CMS system. -categories: + Installs the Drupal CMS. +tags: - applications requires: db: -- GitLab