|
USER=ubuntu # user that will run unicorn and delayed_job |
|
GROUP=ubuntu # group that user belongs to |
|
APP_NAME=myapp # name of directory that will contain your app |
|
INSTALL_PATH=/var/www # parent directory of app |
|
DOMAIN=myapp.com # domain name for nginx |
|
RUBY_VERSION=2.2.2 # version of Ruby to install |
|
KEEP_LOG_DAYS=7 # number of days logrotate will keep logs for |
|
MAX_UPLOAD_SIZE=50m # max file size that nginx will allow to be uploaded |
|
DELAYED_JOB_WORKERS=2 # number of delayed_job workers to run |
|
|
|
# replace variables in setup files |
|
sed -i s#{{APP_NAME}}#$APP_NAME#g /tmp/logrotate.conf |
|
sed -i s#{{KEEP_LOG_DAYS}}#$KEEP_LOG_DAYS#g /tmp/logrotate.conf |
|
sed -i s#{{INSTALL_PATH}}#$INSTALL_PATH#g /tmp/logrotate.conf |
|
sed -i s#{{USER}}#$USER#g /tmp/logrotate.conf |
|
sed -i s#{{GROUP}}#$GROUP#g /tmp/logrotate.conf |
|
|
|
sed -i s#{{APP_NAME}}#$APP_NAME#g /tmp/nginx.conf |
|
sed -i s#{{INSTALL_PATH}}#$INSTALL_PATH#g /tmp/nginx.conf |
|
sed -i s#{{DOMAIN}}#$DOMAIN#g /tmp/nginx.conf |
|
sed -i s#{{MAX_UPLOAD_SIZE}}#$MAX_UPLOAD_SIZE#g /tmp/nginx.conf |
|
|
|
sed -i s#{{APP_NAME}}#$APP_NAME#g /tmp/unicorn.sh |
|
sed -i s#{{INSTALL_PATH}}#$INSTALL_PATH#g /tmp/unicorn.sh |
|
sed -i s#{{USER}}#$USER#g /tmp/unicorn.sh |
|
|
|
sed -i s#{{APP_NAME}}#$APP_NAME#g /tmp/delayed_job.sh |
|
sed -i s#{{INSTALL_PATH}}#$INSTALL_PATH#g /tmp/delayed_job.sh |
|
sed -i s#{{USER}}#$USER#g /tmp/delayed_job.sh |
|
|
|
# install essential ubuntu packages |
|
sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install -y build-essential ntp nginx htop tmux git-core nodejs libmysqlclient-dev imagemagick pkg-config libmagickwand-dev |
|
|
|
# install ruby-install |
|
cd /tmp |
|
wget -O ruby-install-0.7.0.tar.gz https://github.com/postmodern/ruby-install/archive/v0.7.0.tar.gz |
|
tar -xzvf ruby-install-0.7.0.tar.gz |
|
cd ruby-install-0.7.0/ |
|
sudo make install |
|
|
|
# install chruby, add startup scripts in /etc/profile.d/chruby.sh |
|
cd /tmp |
|
wget -O chruby-0.3.9.tar.gz https://github.com/postmodern/chruby/archive/v0.3.9.tar.gz |
|
tar -xzvf chruby-0.3.9.tar.gz |
|
cd chruby-0.3.9/ |
|
sudo make install |
|
printf "if [ -n \"\$BASH_VERSION\" ] || [ -n \"\$ZSH_VERSION\" ]; then\n source /usr/local/share/chruby/chruby.sh\n source /usr/local/share/chruby/auto.sh\nfi\n" > /tmp/chruby.sh && sudo mv /tmp/chruby.sh /etc/profile.d/chruby.sh && sudo chown root:root /etc/profile.d/chruby.sh |
|
printf "$RUBY_VERSION\n" > ~/.ruby-version |
|
|
|
# install ruby and use it |
|
ruby-install ruby $RUBY_VERSION |
|
source /usr/local/share/chruby/chruby.sh |
|
chruby $RUBY_VERSION |
|
|
|
# install bundler |
|
gem install bundler --no-rdoc --no-ri |
|
|
|
# setup web directory |
|
sudo mkdir $INSTALL_PATH && sudo chown $USER:$GROUP $INSTALL_PATH |
|
|
|
# add nginx config in /etc/nginx/sites-available/$APP_NAME.conf and setup link |
|
sudo cp /tmp/nginx.conf /etc/nginx/sites-available/$APP_NAME && sudo chown root:root /etc/nginx/sites-available/$APP_NAME |
|
sudo ln -nsf /etc/nginx/sites-available/$APP_NAME /etc/nginx/sites-enabled/$APP_NAME |
|
|
|
# remove the default "nginx works!" site in nginx |
|
sudo rm /etc/nginx/sites-enabled/default |
|
|
|
# add logrotate config in /etc/logrotate.d/$APP_NAME |
|
sudo cp /tmp/logrotate.conf /etc/logrotate.d/$APP_NAME && sudo chown root:root /etc/logrotate.d/$APP_NAME |
|
|
|
# add unicorn init script in /etc/init.d/unicorn |
|
sudo cp /tmp/unicorn.sh /etc/init.d/unicorn && sudo chown root:root /etc/init.d/unicorn && sudo chmod 755 /etc/init.d/unicorn |
|
|
|
# set run levels for unicorn |
|
sudo update-rc.d unicorn defaults |
|
|
|
# add delayed_job init script in /etc/init.d/delayed_job |
|
sudo cp /tmp/delayed_job.sh /etc/init.d/delayed_job && sudo chown root:root /etc/init.d/delayed_job && sudo chmod 755 /etc/init.d/delayed_job |
|
|
|
# set run levels for delayed_job |
|
sudo update-rc.d delayed_job defaults |
|
|
|
printf "\n\n***********************\nInstall complete! Reboot to start services and clear memory.\n***********************\n" |