closes #3140
[arvados.git] / doc / install / install-api-server.html.textile.liquid
1 ---
2 layout: default
3 navsection: installguide
4 title: Install the API server
5 ...
6
7 h2. Prerequisites:
8
9 # A GNU/Linux (virtual) machine
10 # A domain name for your api server
11
12 h2(#dependencies). Install dependencies
13
14 <notextile>
15 <pre><code>~$ <span class="userinput">sudo apt-get install libcurl3 libcurl3-gnutls libcurl4-openssl-dev \
16     libxslt1.1 zlib1g-dev gettext bison libssl-dev libreadline-dev \
17     libpq-dev sqlite3 libsqlite3-dev build-essential wget postgresql sudo
18 </span></code></pre></notextile>
19
20 h2(#ruby). Install Ruby and bundler
21
22 We recommend Ruby >= 2.1.
23
24 <notextile>
25 <pre><code><span class="userinput">mkdir -p ~/src
26 cd ~/src
27 wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.1.tar.gz
28 tar xzf ruby-2.1.1.tar.gz
29 cd ruby-2.1.1
30 ./configure
31 make
32 sudo make install
33
34 sudo gem install bundler</span>
35 </code></pre></notextile>
36
37 h2. Download the source tree
38
39 <notextile>
40 <pre><code>~$ <span class="userinput">cd $HOME</span> # (or wherever you want to install)
41 ~$ <span class="userinput">git clone https://github.com/curoverse/arvados.git</span>
42 </code></pre></notextile>
43
44 See also: "Downloading the source code":https://arvados.org/projects/arvados/wiki/Download on the Arvados wiki.
45
46 h2. Install gem dependencies
47
48 <notextile>
49 <pre><code>~$ <span class="userinput">cd arvados/services/api</span>
50 ~/arvados/services/api$ <span class="userinput">bundle install</span>
51 </code></pre></notextile>
52
53 h2. Configure the API server
54
55 Edit the main configuration:
56
57 <notextile>
58 <pre><code>~/arvados/services/api$ <span class="userinput">cp -i config/application.yml.example config/application.yml</span>
59 </code></pre></notextile>
60
61 Choose a unique 5-character alphanumeric string to use as your @uuid_prefix@. An example is given that generates a 5-character string based on a hash of your hostname. The @uuid_prefix@ is a unique identifier for your API server. It also serves as the first part of the hostname for your API server.
62
63 For a development site, use your own domain instead of arvadosapi.com.
64
65 Make sure a clone of the arvados repository exists in @git_repositories_dir@:
66
67 <notextile>
68 <pre><code>~/arvados/services/api$ <span class="userinput">sudo mkdir -p /var/cache/git</span>
69 ~/arvados/services/api$ <span class="userinput">sudo git clone --bare ../../.git /var/cache/git/arvados.git</span>
70 </code></pre></notextile>
71
72 Generate a new secret token for signing cookies:
73
74 <notextile>
75 <pre><code>~/arvados/services/api$ <span class="userinput">rake secret</span>
76 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
77 </code></pre></notextile>
78
79 Put it in @config/application.yml@ in the production or common section:
80
81 <notextile>
82 <pre><code><span class="userinput">    secret_token: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</span>
83 </code></pre>
84 </notextile>
85
86 Consult @application.default.yml@ for a full list of configuration options. Always put your local configuration in @application.yml@ instead of editing @application.default.yml@.
87
88 Generate a new database password. Nobody ever needs to memorize it or type it, so we'll make a strong one:
89
90 <notextile>
91 <pre><code>~/arvados/services/api$ <span class="userinput">ruby -e 'puts rand(2**128).to_s(36)'</span>
92 6gqa1vu492idd7yca9tfandj3
93 </code></pre></notextile>
94
95 Create a new database user with permission to create its own databases.
96
97 <notextile>
98 <pre><code>~/arvados/services/api$ <span class="userinput">sudo -u postgres createuser --createdb --encrypted --pwprompt arvados</span>
99 [sudo] password for <b>you</b>: <span class="userinput">yourpassword</span>
100 Enter password for new role: <span class="userinput">paste-password-you-generated</span>
101 Enter it again: <span class="userinput">paste-password-again</span>
102 Shall the new role be a superuser? (y/n) <span class="userinput">n</span>
103 Shall the new role be allowed to create more new roles? (y/n) <span class="userinput">n</span>
104 </code></pre></notextile>
105
106 Configure API server to connect to your database by creating and updating @config/database.yml@. Replace the @xxxxxxxx@ database password placeholders with the new password you generated above.
107
108 <notextile>
109 <pre><code>~/arvados/services/api$ <span class="userinput">cp -i config/database.yml.sample config/database.yml</span>
110 ~/arvados/services/api$ <span class="userinput">edit config/database.yml</span>
111 </code></pre></notextile>
112
113 Create and initialize the database.
114
115 <notextile>
116 <pre><code>~/arvados/services/api$ <span class="userinput">RAILS_ENV=development bundle exec rake db:setup</span>
117 </code></pre></notextile>
118
119 Set up omniauth:
120
121 <notextile>
122 <pre><code>~/arvados/services/api$ <span class="userinput">cp -i config/initializers/omniauth.rb.example config/initializers/omniauth.rb
123 </code></pre></notextile>
124
125 Edit @config/initializers/omniauth.rb@. Set @APP_SECRET@ to the value of @app_secret@ from "installing the single sign on server":install-sso.html .
126
127 You can now run the development server:
128
129 <notextile>
130 <pre><code>~/arvados/services/api$ <span class="userinput">bundle exec rails server --port=3030
131 </code></pre></notextile>
132
133 h3. Apache/Passenger (optional)
134
135 You can use "Passenger":https://www.phusionpassenger.com/ for deployment. Point it to the services/api directory in the source tree.
136
137 To enable streaming so users can monitor crunch jobs in real time, add to your Passenger configuration in Apache:
138
139 <notextile>
140 <pre><code><span class="userinput">PassengerBufferResponse off</span>
141 </code></pre>
142 </notextile>
143
144 h2(#admin-user). Add an admin user
145
146 Point your browser to the API server's login endpoint:
147
148 <notextile>
149 <pre><code><span class="userinput">https://localhost:3030/login</span>
150 </code></pre>
151 </notextile>
152
153 Log in with your google account.
154
155 Use the rails console to give yourself admin privileges:
156
157 <notextile>
158 <pre><code>~/arvados/services/api$ <span class="userinput">bundle exec rails console</span>
159 irb(main):001:0&gt; <span class="userinput">Thread.current[:user] = User.all.select(&:identity_url).last</span>
160 irb(main):002:0&gt; <span class="userinput">Thread.current[:user].is_admin = true</span>
161 irb(main):003:0&gt; <span class="userinput">Thread.current[:user].update_attributes is_admin: true, is_active: true</span>
162 irb(main):004:0&gt; <span class="userinput">User.where(is_admin: true).collect &:email</span>
163 =&gt; ["root", "<b>your_address@example.com</b>"]
164 </code></pre></notextile>