Skip to content

Instantly share code, notes, and snippets.

@viglesiasce
Last active December 11, 2015 01:59
Show Gist options
  • Save viglesiasce/4527791 to your computer and use it in GitHub Desktop.
Save viglesiasce/4527791 to your computer and use it in GitHub Desktop.
Install Scalr on Ubuntu 12.04 Precise Pangolin
#!/bin/bash
export PASSWORD=yourpassword
export HOSTNAME='scalr'
export DOMAIN='.local'
export SCALR_BASE=/usr/local/scalr
export SCALR_HOME=$SCALR_BASE/scalr-home
export SCALR_FILES=$SCALR_BASE/scalr-files
export CURRENT=$SCALR_BASE/current
hostname $HOSTNAME
echo $HOSTNAME > /etc/hostname
echo "127.0.0.1 $HOSTNAME" >> /etc/hosts
chmod -R 777 /tmp/
apt-get -y install apache2-mpm-prefork php5 php5-mysql php5-curl php5-mcrypt \
php5-snmp libssh2-php apparmor-utils mailutils bind9 phpmyadmin \
php-pear rrdtool librrd-dev libcurl4-openssl-dev mysql-server snmp
echo '$cfg["AllowArbitraryServer"] = TRUE;' >> /etc/phpmyadmin/config.inc.php
useradd -d $SCALR_BASE -m -r -G www-data,bind scalr
usermod -G scalr www-data
mkdir -p $SCALR_HOME
mkdir -p $SCALR_FILES
cd $SCALR_FILES
curl -L https://github.com/Scalr/scalr/tarball/master > scalr-master-$(date '+%Y%m%d').tar.gz
cd $SCALR_BASE
tar -zxvf $SCALR_FILES/scalr-master-$(date '+%Y%m%d').tar.gz
ln -sf $(ls -rtd1 Scalr* | tail -1)/app current
ln -sf $(ls -rtd1 Scalr* | tail -1)/sql sql
mkdir -p $SCALR_HOME/etc
touch $SCALR_HOME/etc/.cryptokey
mkdir -p $SCALR_HOME/cache/smarty_bin
chmod 2755 $SCALR_BASE
chmod -R 2775 $SCALR_HOME/cache
cd $CURRENT ; ln -sf $SCALR_HOME/cache ; cd $SCALR_BASE
chmod 2775 $SCALR_HOME/etc/.cryptokey
cd $CURRENT/etc ; ln -sf $SCALR_HOME/etc/.cryptokey ; cd $SCALR_BASE
mkdir -p $SCALR_HOME/graphics
mkdir -p $SCALR_HOME/rrddata
mkdir -p $SCALR_HOME/log
chown -R scalr:scalr $SCALR_BASE
cp -rp $CURRENT/templates/en_US $SCALR_HOME/cache/smarty_bin/
mysql -uroot --password=$PASSWORD -e 'create database scalr; grant all on scalr.* to scalr@localhost identified by "'$PASSWORD'";flush privileges;'
mysql -uroot --password=$PASSWORD -e 'grant all on *.* to admin@localhost identified by "'$PASSWORD'" with grant option;flush privileges;'
mysql -uscalr --password=$PASSWORD scalr < $SCALR_BASE/sql/structure.sql
mysql -uscalr --password=$PASSWORD scalr < $SCALR_BASE/sql/data.sql
perl -i -pe "s/ns1.scalr.net/scalr.example.org/g" $CURRENT/src/class.DBDNSZone.php
cp -p $CURRENT/src/Scalr/Net/Dns/Bind/Transports/LocalFs.php $CURRENT/src/Scalr/Net/Dns/Bind/Transports/LocalFs.php-dist
perl -i -pe 's/\(!\$retval\)/(\$retval === false)/g' $CURRENT/src/Scalr/Net/Dns/Bind/Transports/LocalFs.php
cp -p $CURRENT/src/structs/struct.CONFIG.php $CURRENT/src/structs/struct.CONFIG.php-dist
ip=$(ifconfig eth0 | grep inet | head -1 | awk ' { print $2 } ' | cut -f2 -d:)
perl -i -pe "s/^(.*PMA_INSTANCE_IP_ADDRESS = ).*/\$1 '$ip';/g" $CURRENT/src/structs/struct.CONFIG.php
for i in CPU LA MEM NET; do
mv $CURRENT/cron/watchers/class.${i}SNMPWatcher.php $CURRENT/cron/watchers/class.${i}SNMPWatcher.php-dist
curl https://raw.github.com/ssrini/scalr/master/cron/watchers/class.${i}SNMPWatcher.php > $CURRENT/cron/watchers/class.${i}SNMPWatcher.php
chown scalr:scalr $CURRENT/cron/watchers/class.${i}SNMPWatcher.php
done
for i in RRD RRDGraph; do
mv $CURRENT/src/LibWebta/library/Data/RRD/class.${i}.php $CURRENT/src/LibWebta/library/Data/RRD/class.${i}.php-dist
curl https://raw.github.com/ssrini/scalr/master/src/LibWebta/library/Data/RRD/class.${i}.php > $CURRENT/src/LibWebta/library/Data/RRD/class.${i}.php
chown scalr:scalr $CURRENT/src/LibWebta/library/Data/RRD/class.${i}.php
done
cat <<EOF> /etc/apache2/sites-available/scalr
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName \${HOSTNAME}\${DOMAIN}
DocumentRoot /usr/local/scalr/current/www
ErrorLog \${APACHE_LOG_DIR}/scalr-error.log
CustomLog \${APACHE_LOG_DIR}/scalr-access.log combined
<Directory /usr/local/scalr/current/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
Alias /graphics "/usr/local/scalr/scalr-home/graphics"
<Directory /usr/local/scalr/current/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
</VirtualHost>
EOF
a2ensite scalr
pecl install rrd
echo 'extension=rrd.so' > /etc/php5/apache2/conf.d/rrd.ini
printf '\n\n\n\n' | pecl install pecl_http
echo 'extension=http.so' > /etc/php5/apache2/conf.d/http.ini
a2enmod rewrite
service apache2 restart
[ -f $CURRENT/etc/config.ini ] && mv $CURRENT/etc/config.ini $CURRENT/etc/config.ini-old
cat > $CURRENT/etc/config.ini <<EOF
[db]
driver=mysqli
host = "localhost"
name = "scalr"
user = "scalr"
pass = "$PASSWORD"
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment