-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathserver_setup.sh
executable file
·102 lines (86 loc) · 2.2 KB
/
server_setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
set -e
# Parse option flags.
if [[ $1 = "-d" ]]; then
echo "DEV MODE"
export CDO_DEV=1
export RAILS_ENV=development
shift
else
export RAILS_ENV=production
fi
# Parse positional arguments.
if [[ $# -lt 2 ]]; then
echo 'Usage: server_setup.sh [options] <dash_root> <cdo_user>'
exit 1
fi
export DASH_ROOT=$1
export CDO_USER=$2
export DEBIAN_FRONTEND=noninteractive
aptitude update
# Production service dependencies.
aptitude -y install \
build-essential \
git \
mysql-client \
libssl-dev \
mysql-server \
libmysqlclient-dev \
libreadline-dev \
libncurses-dev \
nginx
# Native dependencies for builds with Node.js.
if [[ $CDO_DEV ]]; then
aptitude -y install \
libcairo2-dev \
libjpeg8-dev \
libpango1.0-dev \
libgif-dev \
g++
fi
export CDO_BUILD_PATH=/usr/src
if [[ ! -f $CDO_BUILD_PATH/ruby-2.0.0-p247.tar.gz ]]; then
wget -P $CDO_BUILD_PATH https://s3.amazonaws.com/cdo-dist/ruby/ruby-2.0.0-p247.tar.gz
tar -C $CDO_BUILD_PATH -xzvf $CDO_BUILD_PATH/ruby-2.0.0-p247.tar.gz
(
cd $CDO_BUILD_PATH/ruby-2.0.0-p247
./configure
make
make install
)
fi
gem install bundler
gem install unicorn
bundle install --gemfile=$DASH_ROOT/Gemfile --binstubs
# Configure Unicorn
unicorn_cfg=/etc/init.d/unicorn
rm -f $unicorn_cfg
sed -e "s|%DASH_ROOT%|$DASH_ROOT|g" \
-e "s|%CDO_USER%|$CDO_USER|g" \
-e "s|%RAILS_ENV%|$RAILS_ENV|g" \
$DASH_ROOT/config/unicorn_init.sh > $unicorn_cfg
chmod +x $unicorn_cfg
$DASH_ROOT/config/unicorn.rb.sh > $DASH_ROOT/config/unicorn.rb
mkdir -p /var/log/unicorn
chown $CDO_USER /var/log/unicorn
/usr/sbin/update-rc.d -f unicorn defaults
# Configure Nginx
$DASH_ROOT/scripts/cfg_nginx
# configure logrotate
cp $DASH_ROOT/config/logrotate /etc/logrotate.d/cdo
logrotate /etc/logrotate.d/cdo
# Configure Node.js
if [[ $CDO_DEV ]]; then
if [[ ! -d $CDO_BUILD_PATH/node-0.10.20 ]]; then
wget -P $CDO_BUILD_PATH https://s3.amazonaws.com/cdo-dist/nodejs/nodejs-v0.10.20.tar.gz
tar -C $CDO_BUILD_PATH -xzvf $CDO_BUILD_PATH/nodejs-v0.10.20.tar.gz
(
cd $CDO_BUILD_PATH/node-0.10.20
./configure
make
make install
)
fi
npm install -g grunt-cli
su -c $DASH_ROOT/dev_setup.sh $CDO_USER
fi