0% found this document useful (0 votes)
140 views4 pages

Digitalocean Ubuntu 14.04

This script configures a server for deployment by: 1. Creating a swap file and enabling swap space. 2. Installing necessary packages like PostgreSQL, Nginx and Ruby development tools. 3. Configuring a deploy user account and setting up rbenv and other tools for development. 4. Configuring log rotation and sudo privileges for deploy user to restart services.

Uploaded by

phong17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
140 views4 pages

Digitalocean Ubuntu 14.04

This script configures a server for deployment by: 1. Creating a swap file and enabling swap space. 2. Installing necessary packages like PostgreSQL, Nginx and Ruby development tools. 3. Configuring a deploy user account and setting up rbenv and other tools for development. 4. Configuring log rotation and sudo privileges for deploy user to restart services.

Uploaded by

phong17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#!

/usr/bin/env bash
mkdir -p ~/.tmux/logs
echo '-> Backup /etc/fstab and ~/.bashrc (root)'
cp /etc/fstab /etc/fstab.backup
cp ~/.bashrc ~/.bashrc.backup
echo '-> Make swap file /var/swap.img'
swapon -s
touch /var/swap.img
chmod 600 /var/swap.img
dd if=/dev/zero of=/var/swap.img bs=1024k count=2000
mkswap /var/swap.img
echo '-> Enable swap'
echo '/var/swap.img
none
swapon /var/swap.img
sysctl -w vm.swappiness=30

swap

sw

0' >> /etc/fstab

echo '-> Disable installing rdoc and ri'


echo 'gem: --no-rdoc --no-ri' > ~/.gemrc
echo '-> Setup ps1 command prompt and aliases'
wget --no-check-certificate https://www.dropbox.com/s/c4q2emo6i2eezn8/ps1.sh?dl=
1 -O ~/.ps1.sh
cat <<CODE >> ~/.bash_aliases
alias uu="sudo apt-get update -y && sudo apt-get dist-upgrade"
alias up="sudo apt-get update -y && sudo apt-get dist-upgrade -y && sudo apt-get
autoclean -y && sudo apt-get autoremove -y"
alias setup-ps1="wget --no-check-certificate https://www.dropbox.com/s/c4q2emo6i
2eezn8/ps1.sh?dl=1 -O ~/.ps1.sh"
CODE
cat <<CODE >> ~/.bashrc
[ -f \$HOME/.ps1.sh ] && source \$HOME/.ps1.sh && ps1_set
CODE
[ -f $HOME/.ps1.sh ] && source $HOME/.ps1.sh && ps1_set
echo '-> Install necessary packages and PostgreSQL and Nginx'
apt-get install -qq software-properties-common python-software-properties -y
add-apt-repository ppa:nginx/stable -y
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" > /e
tc/apt/sources.list.d/trusty-pgdg.list'
wget https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | apt-key add apt-get update -qq -y
apt-get dist-upgrade -qq -y
apt-get install -qq \
htop git-core openssh-server nginx-full vim tmux xsel xclip \
postgresql-9.4 postgresql-client-9.4 libpq5 libpq-dev \
build-essential autoconf automake libtool bison patch \
exuberant-ctags libmagickwand-dev libxml2-dev libxslt1-dev openssl libssl-de
v \
libmemcached-dev libreadline-dev libreadline6 libreadline6-dev \

zlib1g zlib1g-dev libyaml-dev libc6-dev ncurses-term libncurses5-dev \


libgdbm3 libgdbm-dev libcurl4-openssl-dev libffi-dev libevent1-dev imagemagi
ck python-pip -y
pip install -q gsutil
cd
echo '-> Add deploy user'
useradd -G sudo -s /bin/bash -d /home/deploy -U -m deploy
echo '-> Copy ssh dir'
cp -r ~/.ssh /home/deploy/.ssh
chown deploy -R /home/deploy/.ssh
echo '-> Copy default aliases'
cp ~/.bash_aliases /home/deploy/.bash_aliases
chown deploy /home/deploy/.bash_aliases
echo '-> Create deploy login and its database in PostgreSQL'
su - postgres -c <<CODE /bin/bash
createuser -U postgres -d -s deploy
createdb -U postgres -O deploy deploy
CODE
echo '-> Create /etc/sudoers.d/deploy for deployment'
cat <<CODE > /etc/sudoers.d/deploy
deploy ALL=NOPASSWD: /etc/init.d/nginx
deploy
deploy
deploy
deploy
deploy
deploy
deploy
deploy
deploy

ALL=NOPASSWD:
ALL=NOPASSWD:
ALL=NOPASSWD:
ALL=NOPASSWD:
ALL=NOPASSWD:
ALL=NOPASSWD:
ALL=NOPASSWD:
ALL=NOPASSWD:
ALL=NOPASSWD:

/usr/sbin/service
/usr/sbin/service
/usr/sbin/service
/usr/sbin/service
/usr/sbin/service
/usr/sbin/service
/usr/sbin/service
/usr/sbin/service
/usr/sbin/service

nginx
nginx
nginx
nginx
nginx
nginx
nginx
nginx
nginx

start
stop
restart
reload
force-reload
status
configtest
rotate
upgrade

deploy ALL=NOPASSWD: /bin/cp -fv config/nginx-*


x-*
deploy ALL=NOPASSWD: /bin/cp -fv config/puma-*

/etc/nginx/sites-enabled/ngin
/etc/init.d/puma-*

deploy ALL=NOPASSWD: /bin/cp -fv /home/deploy/*/current/config/nginx-*


ginx/sites-enabled/nginx-*
deploy ALL=NOPASSWD: /bin/cp -fv /home/deploy/*/current/config/puma-*
nit.d/puma-*
deploy ALL=NOPASSWD: /bin/rm -fv /etc/nginx/sites-enabled/nginx-*
deploy ALL=NOPASSWD: /bin/rm -fv /etc/init.d/puma-*
CODE
echo '-> Create /etc/logrotate.d/deploy'
cat <<CODE > /etc/logrotate.d/deploy
su deploy deploy

/etc/n
/etc/i

/home/deploy/*/shared/log/*.log {
weekly
rotate 5
missingok
notifempty
compress
create 666 deploy deploy
copytruncate
}
/home/deploy/pgbackup/*.log {
weekly
rotate 5
missingok
notifempty
compress
create 666 deploy deploy
copytruncate
}
CODE
echo '-> Setup rbenv and ps1.sh for deploy user'
su - deploy -c <<CODE /bin/bash
mkdir -p ~/.tmux/logs
cp ~/.bashrc ~/.bashrc.backup
echo 'gem: --no-rdoc --no-ri' > ~/.gemrc
echo '.. Install rbenv'
git clone --quiet https://github.com/sstephenson/rbenv.git
git clone --quiet https://github.com/sstephenson/ruby-build.git
/ruby-build
git clone --quiet https://github.com/jf/rbenv-gemset.git
/rbenv-gemset
git clone --quiet https://github.com/rkh/rbenv-update.git
/rbenv-update

~/.rbenv
~/.rbenv/plugins
~/.rbenv/plugins
~/.rbenv/plugins

echo '.. Download ps1.sh'


wget -q --no-check-certificate https://www.dropbox.com/s/c4q2emo6i2eezn8/ps1.sh?
dl=1 -O ~/.ps1.sh
echo '.. Init rbenv and ps1'
cat <<EOS >> ~/.bash_profile
[ -f \\\$HOME/.bash_aliases ] && source \\\$HOME/.bash_aliases
[ -f \\\$HOME/.ps1.sh ] && source \\\$HOME/.ps1.sh && ps1_set
export EDITOR='vim'
export RUBY_CONFIGURE_OPTS='--disable-install-doc'
export PATH=\\\$HOME/.rbenv/bin:\\\$PATH
if which rbenv >/dev/null 2>&1; then
eval "\\\$(rbenv init -)"
fi
EOS
export PATH=\$HOME/.rbenv/bin:\$PATH
eval "\$(rbenv init -)"

echo ".. Install Ruby and Bundler gem"


rbenv install 2.0.0-p648
rbenv local 2.0.0-p648
gem install --quiet bundler
CODE
echo '-> Change password for deploy user'
passwd deploy
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo

'********** NOTE: TODO LIST **********'


'1. Change password for deploy user in PostgreSQL'
' $ su - postgres -c psql'
' postgres=# \password deploy'
' postgres=# \q'
'2.
'
'
'

Config /etc/nginx/nginx.conf'
$ vim /etc/nginx/nginx.conf'
Change worker_processes from "auto" to "1"'
Uncomment line # server_names_hash_bucket_size 64; (remove #)'

echo
echo '-> Done!'

You might also like