Created
June 29, 2012 23:16
-
-
Save chorrell/3021344 to your computer and use it in GitHub Desktop.
Installing Ruby through rvm and Passenger for Nginx on a SmartMachine
This file contains 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
#!/bin/bash | |
export PS4='${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' | |
# enable xtrace for debugging | |
#set -o xtrace | |
echo " " | |
echo "Setting up the deploy user" | |
echo "------------------------------------------------------" | |
groupadd -g 1008 deploy | |
useradd -c "Deploy User" -d /home/deploy -P "Service Management" \ | |
-g 1008 -m -s /usr/bin/bash -u 1008 deploy | |
# Setup ssh keys | |
chmod 700 /home/deploy/.ssh | |
chmod 700 /home/deploy/.ssh && \ | |
touch /home/deploy/.ssh/authorized_keys && \ | |
chown deploy:deploy /home/deploy/.ssh/authorized_keys | |
echo " " | |
echo "Adding ssh keys for the deploy user" | |
echo "------------------------------------------------------" | |
# XXX fill in your keys here | |
cat >> /home/deploy/.ssh/authorized_keys <<EOF | |
ssh-rsa key1 | |
ssh-rsa key2 | |
... | |
EOF | |
chown deploy:deploy /home/deploy/.ssh/authorized_keys | |
chmod 600 /home/deploy/.ssh/authorized_keys | |
# Setup sudo | |
echo 'deploy ALL=(ALL) NOPASSWD: ALL' >> /opt/local/etc/sudoers | |
passwd -N deploy | |
echo " " | |
echo "Installing packages via pkgsrc" | |
echo "------------------------------------------------------" | |
# XXX fill in required pkgsrc packages | |
pkgin -f up | |
pkglist="gcc-compiler ruby18 curl gmake scmgit libxslt mysql-client-5.5.13 ruby18-RMagick" | |
for pkg in ${pkglist}; do | |
pkgin -y in ${pkg} | |
done | |
echo 'yes' | pkgin -y in sun-jre6-6.0.26 | |
cat > /home/deploy/installer << "__EOF__" | |
#!/bin/bash | |
set -o xtrace | |
# XXX Update any versions here | |
REE_VERSION="ree-1.8.7-2011.03" | |
PASSENGER_VERSION="passenger-3.0.13" | |
NGINX_VERSION="nginx-1.0.11" | |
export PATH="/opt/local/bin:/opt/local/sbin:/usr/bin:/usr/sbin" | |
source /home/deploy/.bash_profile | |
echo " " | |
echo "Installing RVM" | |
echo "------------------------------------------------------" | |
bash -s stable < <( curl -L https://get.rvm.io ) | |
gsed -i "s/\/usr\/gnu\/bin/\/opt\/local\/bin:\/usr\/gnu\/bin/g" /home/deploy/.rvm/src/rvm/scripts/install | |
gsed -i "s/export PATH//g" /home/deploy/.rvm/src/rvm/scripts/functions/installer | |
export LD_RUN_PATH=/opt/local/lib | |
cd /home/deploy/.rvm/src/rvm && \ | |
./scripts/install --path /home/deploy/.rvm | |
source /home/deploy/.bash_profile | |
echo " " | |
echo "Installing REE" | |
echo "------------------------------------------------------" | |
rvm install ${REE_VERSION} --with-openssl-dir=/opt/local | |
rvm use --default ${REE_VERSION} | |
echo " " | |
echo "Installing passenger" | |
echo "------------------------------------------------------" | |
gem install passenger | |
# Fix broken includes (for alloca) in passenger | |
#gsed -i -e "s/#include <cstdlib>/#include <cstdlib>\n#include <stdlib.h>/" \ | |
# ~/.rvm/gems/${REE_VERSION}/gems/${PASSENGER_VERSION}/ext/common/EventedMessageServer.h | |
#gsed -i -e "s/HAS_ALLOCA_H_/HAS_ALLOCA_H/g" \ | |
# ~/.rvm/gems/${REE_VERSION}/gems/${PASSENGER_VERSION}/ext/common/EventedMessageServer.h | |
cd ~/.rvm/gems/${REE_VERSION}/gems/${PASSENGER_VERSION}/ | |
rake nginx | |
echo " " | |
echo "Installing nginx" | |
echo "------------------------------------------------------" | |
cd ~/ | |
mkdir src | |
source /home/deploy/.bash_profile | |
wget -O src/nginx.tar.gz http://www.nginx.org/download/${NGINX_VERSION}.tar.gz | |
cd src | |
tar xvf nginx.tar.gz | |
cd ${NGINX_VERSION} | |
rvm use --default ${REE_VERSION} | |
# XXX add remove any nginx modules here | |
./configure --prefix='/home/deploy/opt/nginx' \ | |
--with-http_ssl_module \ | |
--with-cc-opt='-Wno-error -I /opt/local/include' \ | |
--with-ld-opt='-L /opt/local/lib' \ | |
--with-http_realip_module \ | |
--with-http_stub_status_module \ | |
--add-module="/home/deploy/.rvm/gems/${REE_VERSION}/gems/${PASSENGER_VERSION}/ext/nginx" | |
make && make install | |
svccfg import /home/deploy/nginx.xml | |
exit 0 | |
__EOF__ | |
cat > /home/deploy/nginx.xml << "__XML_EOF__" | |
<?xml version='1.0'?> | |
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'> | |
<service_bundle type='manifest' name='export'> | |
<service name='network/nginx' type='service' version='0'> | |
<create_default_instance enabled='false'/> | |
<single_instance/> | |
<dependency name='filesystem' grouping='require_all' restart_on='error' type='service'> | |
<service_fmri value='svc:/system/filesystem/local'/> | |
</dependency> | |
<dependency name='network' grouping='require_all' restart_on='error' type='service'> | |
<service_fmri value='svc:/milestone/network:default'/> | |
</dependency> | |
<dependency name='filesystem-local' grouping='require_all' restart_on='none' type='service'> | |
<service_fmri value='svc:/system/filesystem/local:default'/> | |
</dependency> | |
<dependency name='autofs' grouping='optional_all' restart_on='error' type='service'> | |
<service_fmri value='svc:/system/filesystem/autofs:default'/> | |
</dependency> | |
<method_context> | |
<method_environment> | |
<envvar name='LD_PRELOAD_32' value='/usr/lib/extendedFILE.so.1'/> | |
</method_environment> | |
</method_context> | |
<exec_method name='start' type='method' exec='/home/deploy/opt/nginx/sbin/nginx -c %{config_file}' timeout_seconds='60'/> | |
<exec_method name='stop' type='method' exec=':kill' timeout_seconds='60'/> | |
<exec_method name='refresh' type='method' exec=':kill -HUP' timeout_seconds='60'/> | |
<property_group name='application' type='application'> | |
<propval name='config_file' type='astring' value='/home/deploy/opt/nginx/conf/nginx.conf'/> | |
</property_group> | |
<property_group name='startd' type='framework'> | |
<propval name='duration' type='astring' value='contract'/> | |
<propval name='ignore_error' type='astring' value='core,signal'/> | |
</property_group> | |
<stability value='Evolving'/> | |
<template> | |
<common_name> | |
<loctext xml:lang='C'>Nginx HTTP daemon</loctext> | |
</common_name> | |
</template> | |
</service> | |
</service_bundle> | |
__XML_EOF__ | |
chown deploy:deploy /home/deploy/nginx.xml | |
chmod 755 /home/deploy/nginx.xml | |
chown deploy:deploy /home/deploy/installer | |
chmod 755 /home/deploy/installer | |
# run the installer as the deploy user | |
su - deploy /home/deploy/installer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment