Last active
October 12, 2015 04:57
-
-
Save trumbitta/3973728 to your computer and use it in GitHub Desktop.
A couple of scripts for gettin ready a web server for Entando
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# expecially tailored for Aruba Cloud (www.cloud.it) | |
# Ubuntu 12.10 | |
# should work weel on any Ubuntu 12.10 with ssh root access | |
# example: cat provision-entando-1-system-update.sh | ssh me@myserver /bin/bash | |
cat <<"EOM" | |
########################################################### | |
# # | |
# 1. UPDATING THE SYSTEM # | |
# # | |
########################################################### | |
Will now update the operative system to the latest release | |
of every package. | |
Starting in 10 seconds. | |
########################################################### | |
EOM | |
sleep 10 && \ | |
# Install everything as root | |
apt-get --yes install byobu wget && \ | |
#byobu-enable && \ | |
wget https://gist.github.com/trumbitta/3953615/raw/f6c24245592dd420c572e2a352ef6a43f86f9472/sources.list -O /etc/apt/sources.list && \ | |
apt-get update && \ | |
apt-get --yes upgrade && \ | |
cat <<"EOM" | |
########################################################### | |
# # | |
# W A R N I N G ! # | |
# # | |
########################################################### | |
This script is giving you 60 seconds to read this before it | |
proceeds with the supposed-to-happen final reboot. | |
Please don't go straight with part 2. | |
If there's no sudoer on the server, please log in JUST | |
AFTER THE REBOOT and ADD IT! | |
Part 2 will do its lot of things, and in the end will cut | |
root user out of the server. | |
So, again: | |
If there's no sudoer on the server, please log in JUST | |
AFTER THE REBOOT and ADD IT! | |
Example: | |
$> adduser myuser | |
[...questions and answers ...] | |
$> adduser myuser sudo | |
########################################################### | |
EOM | |
sleep 60 && \ | |
echo "Rebooting NOW!" && \ | |
reboot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# expecially tailored for Aruba Cloud (www.cloud.it) | |
# Ubuntu 12.04 LTS | |
# should work weel on any Ubuntu 12.04 with ssh root access | |
# example: cat provision-entando-2-system-environment.sh | ssh me@myserver /bin/bash | |
# BEGIN conf | |
# Edit as needed | |
HOST_PUBLIC_IP="123.123.123.123" | |
FQDN="www.mydomain.com" | |
APPNAME="helloentando" | |
PG_USER="uentando" | |
PG_PASSWORD="pentando" | |
ENTANDO_VERSION="3.2.0" | |
# | |
# END conf | |
# Install everything as root | |
cat <<"EOM" | |
########################################################### | |
# # | |
# 2. INSTALLING AND CONFIGURING THE ENVIRONMENT # | |
# # | |
########################################################### | |
Will now install all the necessary software for a typical | |
Entando instance. | |
Starting in 10 seconds. | |
########################################################### | |
EOM | |
sleep 10 && \ | |
echo "### Install: openjdk-7-jdk ant ant-contrib maven2 postgresql libpg-java" && \ | |
apt-get --yes install openjdk-7-jdk ant ant-contrib maven2 postgresql libpg-java && \ | |
echo "### Configure: PostgreSQL" && \ | |
su postgres -c "createuser -d -S -R ${PG_USER}" && \ | |
su postgres -c "psql -c \"alter user ${PG_USER} with password '${PG_PASSWORD}';\"" && \ | |
echo "### Install: xvfb" && \ | |
apt-get install --yes xvfb && \ | |
echo "### Configure: xvfb" && \ | |
wget https://gist.github.com/raw/3953615/eb6f32a9b5735d7d20d7073026d89a39649dff0f/xvfbd -O /etc/init.d/xvfbd && \ | |
chmod a+x /etc/init.d/xvfbd && \ | |
update-rc.d xvfbd defaults && \ | |
service xvfbd stop ; service xvfbd start && \ | |
echo "### Install: tomcat6" && \ | |
apt-get install --yes tomcat6 && \ | |
service tomcat6 stop && \ | |
echo "### Configure: tomcat6" && \ | |
ln -s /usr/share/java/postgresql-jdbc3-9.1.jar /usr/share/tomcat6/lib/postgresql.jar && \ | |
wget https://gist.github.com/raw/3953615/66e98bb6f472974339766d87d930331dd78ea274/tomcat6_web.xml -O /var/lib/tomcat6/conf/web.xml && \ | |
wget https://gist.github.com/raw/3953615/c90fd1611e13ec1753e857949c7fa9fbe87d7799/etc_initd_tomcat6 -O /etc/init.d/tomcat6 && \ | |
wget https://gist.github.com/raw/3953615/57eee1be71f7960aa4c84cee0c65f346ed3d5d46/etc_default_tomcat6 -O /etc/default/tomcat6 && \ | |
echo "### Install: apache2 libapache2-mod-jk" && \ | |
apt-get install --yes apache2 libapache2-mod-jk && \ | |
echo "### Configure: apache2" && \ | |
echo "${HOST_PUBLIC_IP} ${FQDN}" >> /etc/hosts && \ | |
wget https://gist.github.com/raw/3953615/0cfbf0cbf669d856bfc54a0087618c6835eba756/tomcat6_server.xml -O /var/lib/tomcat6/conf/server.xml && \ | |
a2dismod jk && \ | |
service apache2 restart && \ | |
wget https://gist.github.com/raw/3953615/a1fd73a6dc72740b9bfc149c711294b4fc338a1b/jk.conf -O /etc/apache2/mods-available/jk.conf && \ | |
wget https://gist.github.com/raw/3953615/56f4a30ecfef1c49e97f3f26b8487ad53cce5334/workers.properties -O /etc/libapache2-mod-jk/workers.properties && \ | |
a2enmod jk && \ | |
service apache2 restart && \ | |
wget https://gist.github.com/raw/3953615/938f9a0d4eeb13826b50dc2be04d241b88f8bba1/VirtualHost -O - | sed s/FQDN/${FQDN}/g | sed s/APPNAME/${APPNAME}/g > /etc/apache2/sites-available/${FQDN} && \ | |
mkdir /var/www/${FQDN} && \ | |
chown -R www-data:www-data /var/www/${FQDN}/ && \ | |
su www-data -c "mkdir /var/www/${FQDN}/${APPNAME}" && \ | |
su www-data -c "mkdir /var/www/${FQDN}/${APPNAME}/resources" && \ | |
su www-data -c "ln -s /var/lib/tomcat6/webapps/${APPNAME}/resources/cms /var/www/${FQDN}/${APPNAME}/resources/" && \ | |
su www-data -c "ln -s /var/lib/tomcat6/webapps/${APPNAME}/resources/plugins /var/www/${FQDN}/${APPNAME}/resources/" && \ | |
a2enmod rewrite && \ | |
service apache2 restart && \ | |
a2ensite ${FQDN} && \ | |
service apache2 reload && \ | |
echo "### Install: imagemagick" && \ | |
apt-get install --yes imagemagick && \ | |
echo "### Configure: java default" && \ | |
update-alternatives --set java /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java && \ | |
update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-i386/bin/javac && \ | |
echo "### Prepare: Entando" && \ | |
mkdir ~/Work && \ | |
mkdir ~/Work/Deploy && \ | |
cd ~/Work/Deploy/ && \ | |
mvn archetype:generate -DarchetypeGroupId=org.entando.entando -DarchetypeArtifactId=entando-archetype-portal-generic -DarchetypeVersion=${ENTANDO_VERSION} -DgroupId=${APPNAME} -DartifactId=${APPNAME} -Dversion=1.0-SNAPSHOT -DinteractiveMode=false && \ | |
cd ${APPNAME} && \ | |
sed "s#<property name=\"postgres.username\".*#<property name=\"postgres.username\" value=\"${PG_USER}\" />#g" -i buildProperties.xml | |
sed "s#<property name=\"postgres.password\".*#<property name=\"postgres.password\" value=\"${PG_PASSWORD}\" />#g" -i buildProperties.xml | |
ant PG-db-create && \ | |
sed -e "s/www\.mydomain\.com/${FQDN}/g" -e "s#/opt/tomcat6#/var/lib/tomcat6#g" -e "s/profile\.database\.username=.*$/profile.database.username=${PG_USER}/g" -e "s/profile\.database\.password=.*$/profile.database.password=${PG_PASSWORD}/g" -i src/main/filters/filter-production.properties && \ | |
DEFAULTDB=PostgreSQL | |
FILTERP="src/main/filters/filter-production.properties" | |
DB_ACTIVE=`cat ${FILTERP} | grep -B1 ^profile.database.ho | grep "Database" | awk -F " " '{print $5}'` | |
if [ "${DB_ACTIVE}" == "" ]; | |
then | |
DB_ACTIVE=`cat ${FILTERP} | grep -B1 ^profile.database.ho | grep "Sample" | awk -F " " '{print $3}'` | |
fi | |
if [ "${DB_ACTIVE}" == "" ]; then | |
echo "Unexpected configuration file" | |
exit | |
fi | |
echo "Active database found: $DB_ACTIVE" | |
if [ "$DEFAULTDB" == "$DB_ACTIVE" ]; then | |
echo "Already configured for $DEFAULTDB. Nothing to do here." | |
else | |
echo "Swapping $DB_ACTIVE with $DEFAULTDB" | |
if [ "$DEFAULTDB" == "PostgreSQL" ]; then | |
#Deactivate first the active one dbms | |
sed -e "/${DB_ACTIVE}/,/Serv/{;s/^p/#p/}" -i "${FILTERP}" | |
#Activate only selected database | |
sed -e "/${DEFAULTDB}/,/Serv/{;s/^#p/p/}" -i "${FILTERP}" | |
fi | |
if [ "$DEFAULTDB" == "MySQL" ]; then | |
#Deactivate first the active one dbms | |
sed -e "/${DB_ACTIVE}/,/Serv/{;s/^p/#p/}" -i "${FILTERP}" | |
#Activate only selected database | |
sed -e "/${DEFAULTDB}/,/Serv/{;s/^#p/p/}" -i "${FILTERP}" | |
fi | |
if [ "$DEFAULTDB" == "DERBY" ]; then | |
#Deactivate first the active one dbms | |
sed -e "/${DB_ACTIVE}/,/Serv/{;s/^p/#p/}" -i "${FILTERP}" | |
#Activate only selected database | |
sed -e "/${DEFAULTDB}/,/Serv/{;s/^#p/p/}" -i "${FILTERP}" | |
fi | |
fi | |
echo "### Enabling imagemagick" && \ | |
sed "s#^imagemagick.enabled.*#imagemagick.enabled=true##" -i src/main/config/systemParams.properties && \ | |
echo "### Prepare: WAR" && \ | |
ant WAR-build && \ | |
sudo -u tomcat6 cp target/${APPNAME}.war /var/lib/tomcat6/webapps && \ | |
sudo -u tomcat6 unzip /var/lib/tomcat6/webapps/${APPNAME}.war -d /var/lib/tomcat6/webapps/${APPNAME} && \ | |
sudo -u tomcat6 rm /var/lib/tomcat6/webapps/${APPNAME}.war && \ | |
echo "### Deploy: WAR" && \ | |
service tomcat6 start && \ | |
echo "### Tomcat is starting... sleeping 10 seconds..." && \ | |
sleep 10 && \ | |
echo "### ...awake." && \ | |
echo "### Configure: disable SSH root access" && \ | |
sed "s#PermitRoot.*#PermitRootLogin\ no##" -i /etc/ssh/sshd_config && \ | |
echo "### root access via ssh disabled" && \ | |
echo "### rebooting in 5 seconds" && \ | |
sleep 5 && \ | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment