forked from JuliaCloud/JuliaBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·139 lines (107 loc) · 4.13 KB
/
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
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
#! /usr/bin/env bash
# On Ubuntu 13.04, amd64, Ubuntu provided ami image
# ami-ef277b86
source ${PWD}/jdockcommon.sh
function usage {
echo
echo 'Usage: ./setup.sh -u <admin_username> optional_args'
echo ' -u <username> : Mandatory admin username. If -g option is used, this must be the complete Google email-id'
echo ' -d : Only recreate docker image - do not install/update other software'
echo ' -g : Use Google Openid for user authentication '
echo ' -n <num> : Maximum number of active containers. Deafult 10.'
echo ' -t <seconds> : Auto delete containers older than specified seconds. 0 means never expire. Default 0.'
echo
echo 'Post setup, additional configuration parameters may be set in jdock.user '
echo 'Please see README.md for more details '
exit 1
}
OPT_INSTALL=1
OPT_GOOGLE=0
NUM_LOCALMAX=10
EXPIRE=0
while getopts "u:dgn:t:" FLAG
do
if test $FLAG == '?'
then
usage
elif test $FLAG == 'u'
then
ADMIN_USER=$OPTARG
elif test $FLAG == 'd'
then
OPT_INSTALL=0
elif test $FLAG == 'g'
then
OPT_GOOGLE=1
elif test $FLAG == 'n'
then
NUM_LOCALMAX=$OPTARG
elif test $FLAG == 't'
then
EXPIRE=$OPTARG
fi
done
if test -v $ADMIN_USER
then
usage
fi
#echo $ADMIN_USER $OPT_INSTALL $OPT_GOOGLE
if test $OPT_INSTALL -eq 1; then
# Stuff required for docker and openresty
sudo apt-get -y install build-essential libreadline-dev libncurses-dev libpcre3-dev libssl-dev netcat git python-setuptools supervisor
# INSTALL docker as per http://docs.docker.io/en/latest/installation/ubuntulinux/
sudo apt-get -y update
sudo apt-get -y install linux-image-extra-`uname -r`
sudo sh -c "wget -qO- https://get.docker.io/gpg | apt-key add -"
sudo sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
sudo apt-get -y update
sudo apt-get -y install lxc-docker
# docker stuff
sudo gpasswd -a $USER docker
# nginx
sudo mkdir -p /tmp/resty
sudo wget -P /tmp/resty http://openresty.org/download/ngx_openresty-1.4.3.3.tar.gz
sudo bash -c "cd /tmp/resty; tar -xvzf ngx_openresty-1.4.3.3.tar.gz; cd ngx_openresty-1.4.3.3; ./configure ; make; make install"
sudo rm -Rf /tmp/resty
sudo mkdir -p /usr/local/openresty/lualib/resty/http
sudo cp -f libs/lua-resty-http-simple/lib/resty/http/simple.lua /usr/local/openresty/lualib/resty/http/
# python stuff
sudo easy_install tornado
sudo easy_install futures
git clone https://github.com/dotcloud/docker-py
cd docker-py
sudo python setup.py install
cd ..
fi
# On EC2 we use the ephemeral storage for the images and the docker aufs filsystem store.
sudo mkdir -p /mnt/docker
sudo service docker stop
if grep -q "^DOCKER_OPTS" /etc/default/docker ; then
echo "/etc/default/docker has an entry for DOCKER_OPTS..."
echo "Please ensure DOCKER_OPTS has option '-g /mnt/docker' to use ephemeral storage (on EC2) "
else
echo "Configuring docker to use /mnt/docker for image/container storage"
sudo sh -c "echo 'DOCKER_OPTS=\" -g /mnt/docker \"' >> /etc/default/docker"
fi
sudo service docker start
# Wait for the docker process to bind to the required ports
sleep 1
echo "Building docker image ..."
sudo docker build -t ijulia docker/IJulia/
echo "Setting up nginx.conf"
sed s/\$\$NGINX_USER/$USER/g $NGINX_CONF_DIR/nginx.conf.tpl > $NGINX_CONF_DIR/nginx.conf
sed -i s/\$\$ADMIN_KEY/$1/g $NGINX_CONF_DIR/nginx.conf
echo "Generating random session validation key"
SESSKEY=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c10`
sed -i s/\$\$SESSKEY/$SESSKEY/g $NGINX_CONF_DIR/nginx.conf
sed s/\$\$SESSKEY/$SESSKEY/g $TORNADO_CONF_DIR/tornado.conf.tpl > $TORNADO_CONF_DIR/tornado.conf
if test $OPT_INSTALL -eq 1; then
sed -i s/\$\$GAUTH/True/g $TORNADO_CONF_DIR/tornado.conf
else
sed -i s/\$\$GAUTH/False/g $TORNADO_CONF_DIR/tornado.conf
fi
sed -i s/\$\$ADMIN_USER/$ADMIN_USER/g $TORNADO_CONF_DIR/tornado.conf
sed -i s/\$\$NUM_LOCALMAX/$NUM_LOCALMAX/g $TORNADO_CONF_DIR/tornado.conf
sed -i s/\$\$EXPIRE/$EXPIRE/g $TORNADO_CONF_DIR/tornado.conf
echo
echo "DONE!"