forked from simpx/scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstackscript
177 lines (162 loc) · 6.4 KB
/
stackscript
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
#
# See: https://github.com/simpx/scripts/blob/master/stackscript
# Install: Ruby 1.9.3, Nodejs 0.8.15, Mongodb and Nginx
# Reference: https://www.linode.com/stackscripts/view/?StackScriptID=1291
#
# <UDF name="rr_env" Label="Rails/Rack environment to run" default="production" />
# <UDF name="deploy_user" Label="Username of deploy user" default="deploy" />
# <UDF name="deploy_psw" Label="Password of deploy user" default="" />
#exec &> /root/stackscript.log
# Update packages and install essentials
cd /tmp
echo "Start to install! Good Luck!"
apt-get update
apt-get -y install aptitude
aptitude -y full-upgrade
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-gplv2-dev openssh-server libyaml-dev libcurl4-openssl-dev libxslt-dev libxml2-dev libpcre3 libpcre3-dev
aptitude -y install wget vim less
sed -i -e 's/^#PS1=/PS1=/' /root/.bashrc # enable the colorful root bash prompt
sed -i -e "s/^#alias ll='ls -l'/alias ll='ls -al'/" /root/.bashrc # enable ll list long alias <3
echo "alias cl='clear&&ls'" >> /root/.bashrc
echo "Essentials installed"
# Install nodejs for javascript runtime
export NODEJS_VERSION="v0.8.15"
echo "Installing Nodejs $NODEJS_VERSION"
echo "Downloading: (from calling wget http://nodejs.org/dist/$NODEJS_VERSION/node-$NODEJS_VERSION.tar.gz)"
wget http://nodejs.org/dist/$NODEJS_VERSION/node-$NODEJS_VERSION.tar.gz
echo "Extracting the file"
tar xzf node-$NODEJS_VERSION.tar.gz
cd node-$NODEJS_VERSION
echo "current directory: `pwd`"
echo "Nodejs Configuration output: (from calling ./configure)"
./configure
echo "Nodejs make output: (form calling make)"
make
echo "Nodejs make install output: (from calling make install)"
make install
cd ..
echo "Nodejs installed"
# Install Redis
export REDIS_VERSION="redis-2.6.7"
echo "Installing Redis $REDIS_VERSION"
echo "Downloading: (from calling wget http://redis.googlecode.com/files/$REDIS_VERSION.tar.gz)"
wget http://redis.googlecode.com/files/$REDIS_VERSION.tar.gz
tar xzf $REDIS_VERSION.tar.gz
cd $REDIS_VERSION
./configure
make
make install
# Download Configuration for redis
echo "Downloading Configuration files"
wget https://raw.github.com/simpx/scripts/master/redis.conf
wget https://raw.github.com/simpx/scripts/master/redis-server
mv redis-server /etc/init.d/redis-server
chmod +x /etc/init.d/redis-server
mv redis.conf /etc/redis.conf
# Add redis user
echo "Add Redis user"
mkdir -p /var/lib/redis
mkdir -p /var/log/redis
useradd --system --home-dir /var/lib/redis redis
chown redis.redis /var/lib/redis
chown redis.redis /var/log/redis
# Start redis-server during boot and stop during shutdown
update-rc.d redis-server defaults
cd ..
# Installing Ruby
export RUBY_VERSION="ruby-1.9.3-p194"
echo "Installing Ruby $RUBY_VERSION"
echo "Downloading: (from calling wget http://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz)"
wget http://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz
echo "tar output:"
tar xzf $RUBY_VERSION.tar.gz
cd $RUBY_VERSION
echo "current directory: `pwd`"
echo "Ruby Configuration output: (from calling ./configure)"
./configure
echo "Ruby make output: (from calling make)"
make
echo "Ruby make install output: (from calling make install)"
make install
cd ..
echo "Ruby installed!"
# Set up Nginx
export NGINX_VERSION="nginx-1.2.5"
echo "Installing Nginx $NGINX_VERSION"
echo "Downloading: (from calling wget http://nginx.org/download/$NGINX_VERSION.tar.gz)"
wget http://nginx.org/download/$NGINX_VERSION.tar.gz
echo "tar output:"
tar xzf $NGINX_VERSION.tar.gz
cd $NGINX_VERSION
echo "current directory: `pwd`"
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
make
make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
wget https://raw.github.com/simpx/scripts/master/nginx
mv nginx /etc/init.d/nginx
chmod +x /etc/init.d/nginx
cd ..
# Start nginx during boot and stop during shutdown
update-rc.d -f nginx defaults
# Install git
echo "Installing Git"
apt-get -y install git-core
# Set up rails environment
if [ ! -n "$RR_ENV" ]; then
RR_ENV="production"
fi
cat >> /etc/environment << EOF
RAILS_ENV="$RR_ENV"
RACK_ENV="$RR_ENV"
EOF
# Installing Rails 3
gem update --system
# Install rails
echo "Installing Rails3 and gems"
gem install rails --no-ri --no-rdoc
#Install sqlite
apt-get -y install sqlite3 libsqlite3-dev
gem install sqlite3 --no-ri --no-rdoc
#Install mongo gem
gem install mongoid bson_ext --no-ri --no-rdoc
# Install mongodb
echo "Installing Mongodb"
apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" >> /etc/apt/sources.list
apt-get update
apt-get install mongodb-10gen
# Install mosh
apt-get -y install python-software-properties
add-apt-repository -y ppa:keithw/mosh
apt-get update
apt-get -y install mosh
# Install supervisor
apt-get -y install python-setuptools
easy_install supervisor
mkdir -p /etc/supervisor/conf.d
mkdir -p /var/log/supervisor
wget -P /etc https://raw.github.com/simpx/scripts/master/supervisord.conf
wget -P /etc/supervisor/conf.d https://raw.github.com/simpx/scripts/master/supervisor-sample.conf
supervisord
# Add deploy user
if [ ! -n "$DEPLOY_USER" ]; then
DEPLOY_USER="deploy"
fi
if [ ! -n "$DEPLOY_PSW" ]; then
DEPLOY_PSW="OMG_ITS_MY_PASSWORD!"
fi
echo "Add deploy user: $DEPLOY_USER"
echo "$DEPLOY_USER:$DEPLOY_PSW:1000:1000::/home/$DEPLOY_USER:/bin/bash" | newusers
cp -a /etc/skel/.[a-z]* /home/$DEPLOY_USER/
chown -R $DEPLOY_USER /home/$DEPLOY_USER
# Add to sudoers without password
echo "$DEPLOY_USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# Goodstuff
sed -i -e 's/^#PS1=/PS1=/' /home/$DEPLOY_USER/.bashrc # enable the colorful bash prompt
sed -i -e "s/^#alias ll='ls -l'/alias ll='ls -al'/" /home/$DEPLOY_USER/.bashrc # enable ll list long alias <3
echo "alias cl='clear&&ls -p'" >> /home/$DEPLOY_USER/.bashrc
echo "alias s='sudo supervisorctl'" >> /home/$DEPLOY_USER/.bashrc
# Finished
echo "StackScript Finished!"