HowTo Install Redmine 12x with Mercurial and Subversion on Ubuntu Server 1004 » History » Version 31

Dimitry Profus, 2011-09-20 05:51

1 1 Dimitry Profus
h1. HowTo Install Redmine 1.2.x with Mercurial and Subversion on Ubuntu Server 10.04
2 1 Dimitry Profus
3 1 Dimitry Profus
{{toc}}
4 1 Dimitry Profus
5 1 Dimitry Profus
h2. Redmine Installation
6 1 Dimitry Profus
7 1 Dimitry Profus
# Install the LAMP stack
8 1 Dimitry Profus
<pre>
9 1 Dimitry Profus
$ sudo tasksel install lamp-server
10 1 Dimitry Profus
</pre>
11 1 Dimitry Profus
# Install the required packages
12 1 Dimitry Profus
<pre>
13 1 Dimitry Profus
$ sudo apt-get install build-essential subversion llibmysqlclient15-dev libdigest-sha1-perl libgemplugin-ruby libgemplugin-ruby1.8 libruby-extras libruby1.8-extras rails rake ruby rubygems rubygems1.8 ruby1.8-dev libopenssl-ruby1.8 
14 1 Dimitry Profus
</pre>
15 1 Dimitry Profus
# Install the required Ruby gems
16 1 Dimitry Profus
<pre>
17 1 Dimitry Profus
$ sudo gem install rails -v=2.3.11 --no-ri --no-rdoc
18 1 Dimitry Profus
$ sudo gem install rake -v=0.8.7 --no-ri --no-rdoc
19 1 Dimitry Profus
$ sudo gem uninstall rake -v=0.9.2 
20 1 Dimitry Profus
$ sudo gem install i18n -v=0.4.2 --no-ri --no-rdoc
21 1 Dimitry Profus
$ sudo gem install mysql --no-ri --no-rdoc
22 1 Dimitry Profus
</pre> 
23 1 Dimitry Profus
# Download Redmine into /user/share/redmine directory
24 1 Dimitry Profus
<pre>
25 1 Dimitry Profus
$ sudo svn co http://redmine.rubyforge.org/svn/branches/1.2-stable /usr/share/redmine
26 1 Dimitry Profus
</pre>
27 1 Dimitry Profus
# Create an empty MySQL database and accompanying user named redmine for example.
28 1 Dimitry Profus
<pre>
29 1 Dimitry Profus
$ mysql -u root -p
30 1 Dimitry Profus
(enter the mysql root user password)
31 1 Dimitry Profus
> create database redmine character set utf8;
32 1 Dimitry Profus
> create user 'redmine'@'localhost' identified by '[password]';
33 1 Dimitry Profus
> grant all privileges on redmine.* to 'redmine'@'localhost' identified by '[password]';
34 1 Dimitry Profus
> exit
35 1 Dimitry Profus
</pre>
36 1 Dimitry Profus
# Copy config/database.yml.example to config/database.yml and edit this file in order to configure your database settings for "production" environment.
37 1 Dimitry Profus
<pre>
38 1 Dimitry Profus
$ sudo cp /usr/share/redmine/config/database.yml.example /usr/share/redmine/config/database.yml
39 1 Dimitry Profus
40 1 Dimitry Profus
$ sudo nano /usr/share/redmine/config/database.yml
41 1 Dimitry Profus
42 1 Dimitry Profus
Modify to the following and save (ctrl+x)
43 1 Dimitry Profus
44 1 Dimitry Profus
production:
45 1 Dimitry Profus
  adapter: mysql
46 1 Dimitry Profus
  socket: /var/run/mysqld/mysqld.sock
47 1 Dimitry Profus
  database: redmine
48 1 Dimitry Profus
  host: localhost
49 1 Dimitry Profus
  username: redmine
50 1 Dimitry Profus
  password: [password]
51 1 Dimitry Profus
  encoding: utf8
52 1 Dimitry Profus
</pre>
53 1 Dimitry Profus
# Generate a session store secret.
54 1 Dimitry Profus
<pre>
55 1 Dimitry Profus
$ cd /usr/share/redmine
56 1 Dimitry Profus
57 1 Dimitry Profus
$ sudo rake generate_session_store
58 1 Dimitry Profus
</pre>
59 1 Dimitry Profus
# Create the database structure, by running the following command under the application root directory:
60 1 Dimitry Profus
<pre>
61 1 Dimitry Profus
$ cd /usr/share/redmine
62 1 Dimitry Profus
63 1 Dimitry Profus
$ sudo rake db:migrate RAILS_ENV="production" 
64 1 Dimitry Profus
</pre>
65 1 Dimitry Profus
# Insert default configuration data in database, by running the following command:
66 1 Dimitry Profus
<pre>
67 1 Dimitry Profus
$ sudo RAILS_ENV=production rake redmine:load_default_data
68 1 Dimitry Profus
</pre>
69 1 Dimitry Profus
# Setting up permissions
70 1 Dimitry Profus
<pre>
71 1 Dimitry Profus
$ cd /usr/share/redmine
72 1 Dimitry Profus
$ sudo chown -R www-data:www-data files log tmp public/plugin_assets
73 1 Dimitry Profus
$ sudo chmod -R 755 files log tmp public/plugin_assets
74 1 Dimitry Profus
</pre>
75 1 Dimitry Profus
# Test using the webrick web server
76 1 Dimitry Profus
<pre>
77 1 Dimitry Profus
$ cd /usr/share/redmine
78 1 Dimitry Profus
79 1 Dimitry Profus
$ ruby script/server webrick -e production
80 1 Dimitry Profus
81 1 Dimitry Profus
Point your web browser at http://[my server ip]:3000
82 1 Dimitry Profus
83 1 Dimitry Profus
You should now see the application welcome page.
84 1 Dimitry Profus
</pre>
85 1 Dimitry Profus
86 1 Dimitry Profus
87 1 Dimitry Profus
h2. Apache Integration
88 1 Dimitry Profus
89 1 Dimitry Profus
# Install the required packages
90 1 Dimitry Profus
<pre>
91 1 Dimitry Profus
$ sudo apt-get install libapache2-mod-passenger
92 1 Dimitry Profus
</pre>
93 1 Dimitry Profus
# Add a symbolic link to the public redmine web directory
94 1 Dimitry Profus
<pre>
95 1 Dimitry Profus
$ sudo ln -s /usr/share/redmine/public /var/www/redmine
96 1 Dimitry Profus
</pre>
97 1 Dimitry Profus
# Configure Passanger to run as www-data
98 1 Dimitry Profus
<pre>
99 1 Dimitry Profus
$ sudo nano /etc/apache2/mods-available/passenger.conf
100 1 Dimitry Profus
101 1 Dimitry Profus
Add the follow line and save (ctrl+x)
102 1 Dimitry Profus
103 1 Dimitry Profus
PassengerDefaultUser www-data
104 1 Dimitry Profus
</pre>
105 1 Dimitry Profus
# Create a new Apache site file
106 1 Dimitry Profus
<pre> 
107 1 Dimitry Profus
$ sudo nano /etc/apache2/sites-available/redmine 
108 1 Dimitry Profus
</pre>
109 1 Dimitry Profus
Add the following lines and save (ctrl+x)
110 1 Dimitry Profus
<pre>
111 1 Dimitry Profus
<VirtualHost *:80>
112 1 Dimitry Profus
        ServerAdmin webmaster@localhost
113 1 Dimitry Profus
        DocumentRoot /var/www
114 1 Dimitry Profus
        ServerName myservername
115 1 Dimitry Profus
        
116 1 Dimitry Profus
        RewriteEngine on
117 1 Dimitry Profus
        RewriteRule   ^/$  /redmine  [R]
118 1 Dimitry Profus
119 1 Dimitry Profus
        <Directory /var/www/redmine>
120 1 Dimitry Profus
                RailsBaseURI /redmine
121 1 Dimitry Profus
                PassengerResolveSymlinksInDocumentRoot on
122 1 Dimitry Profus
        </Directory>
123 1 Dimitry Profus
124 1 Dimitry Profus
        ErrorLog /var/log/apache2/error.log
125 1 Dimitry Profus
126 1 Dimitry Profus
        # Possible values include: debug, info, notice, warn, error, crit,
127 1 Dimitry Profus
        # alert, emerg.
128 1 Dimitry Profus
        LogLevel warn
129 1 Dimitry Profus
130 1 Dimitry Profus
        CustomLog /var/log/apache2/access.log combined
131 1 Dimitry Profus
</VirtualHost>
132 1 Dimitry Profus
</pre>
133 1 Dimitry Profus
For SSL add the following text instead
134 1 Dimitry Profus
<pre>
135 1 Dimitry Profus
<VirtualHost *:443>
136 1 Dimitry Profus
        ServerAdmin webmaster@localhost
137 1 Dimitry Profus
        DocumentRoot /var/www
138 1 Dimitry Profus
        ServerName myservername
139 1 Dimitry Profus
140 1 Dimitry Profus
        SSLEngine On
141 1 Dimitry Profus
        SSLCertificateFile /etc/apache2/ssl/redmine.pem
142 1 Dimitry Profus
143 1 Dimitry Profus
        RewriteEngine on
144 1 Dimitry Profus
        RewriteRule   ^/$  /redmine  [R]
145 1 Dimitry Profus
146 1 Dimitry Profus
        <Directory /var/www/redmine>
147 1 Dimitry Profus
                RailsBaseURI /redmine
148 1 Dimitry Profus
                PassengerResolveSymlinksInDocumentRoot on
149 1 Dimitry Profus
        </Directory>
150 1 Dimitry Profus
151 1 Dimitry Profus
        ErrorLog /var/log/apache2/error.log
152 1 Dimitry Profus
153 1 Dimitry Profus
        # Possible values include: debug, info, notice, warn, error, crit,
154 1 Dimitry Profus
        # alert, emerg.
155 1 Dimitry Profus
        LogLevel warn
156 1 Dimitry Profus
157 1 Dimitry Profus
        CustomLog /var/log/apache2/access.log combined
158 1 Dimitry Profus
</VirtualHost>
159 1 Dimitry Profus
</pre>
160 1 Dimitry Profus
# Enable the Redmine website
161 1 Dimitry Profus
<pre>
162 1 Dimitry Profus
$ sudo a2dissite default
163 1 Dimitry Profus
$ sudo a2ensite redmine
164 1 Dimitry Profus
</pre> 
165 1 Dimitry Profus
# Enable the Passenger and Rewite modules and restart Apache
166 5 Dimitry Profus
<pre>
167 1 Dimitry Profus
$ sudo a2enmod passenger
168 1 Dimitry Profus
$ sudo a2enmod rewrite
169 1 Dimitry Profus
$ sudo /etc/init.d/apache2 restart
170 1 Dimitry Profus
</pre> 
171 1 Dimitry Profus
# Test the setup
172 1 Dimitry Profus
<pre>
173 1 Dimitry Profus
Open up your favorite web browser and goto
174 1 Dimitry Profus
175 1 Dimitry Profus
http://[my site or ip]/redmine
176 1 Dimitry Profus
</pre>
177 1 Dimitry Profus
178 1 Dimitry Profus
h2. Mercurial Integration
179 1 Dimitry Profus
180 1 Dimitry Profus
# Install the latest Mercurial release 
181 1 Dimitry Profus
<pre>
182 1 Dimitry Profus
$ sudo apt-get install python-software-properties
183 1 Dimitry Profus
$ sudo add-apt-repository ppa:mercurial-ppa/releases
184 1 Dimitry Profus
$ sudo apt-get update
185 1 Dimitry Profus
$ sudo apt-get install mercurial libapache-dbi-perl libapache2-mod-perl2
186 1 Dimitry Profus
</pre>
187 1 Dimitry Profus
# Create the hg web directory
188 1 Dimitry Profus
<pre>
189 12 Dimitry Profus
$ sudo mkdir -p /var/hg/repos
190 1 Dimitry Profus
</pre>
191 1 Dimitry Profus
# Create the web cgi script file
192 1 Dimitry Profus
<pre>
193 12 Dimitry Profus
$ sudo nano /var/hg/hgwebdir.cgi
194 1 Dimitry Profus
195 1 Dimitry Profus
Add the following and save
196 1 Dimitry Profus
197 1 Dimitry Profus
#!/usr/bin/env python
198 1 Dimitry Profus
#
199 1 Dimitry Profus
from mercurial import demandimport; demandimport.enable()
200 1 Dimitry Profus
from mercurial.hgweb.hgwebdir_mod import hgwebdir
201 1 Dimitry Profus
import mercurial.hgweb.wsgicgi as wsgicgi
202 1 Dimitry Profus
application = hgwebdir('hgweb.config')
203 1 Dimitry Profus
wsgicgi.launch(application)
204 1 Dimitry Profus
</pre>
205 1 Dimitry Profus
# Create the cgi web config file 
206 1 Dimitry Profus
<pre>
207 12 Dimitry Profus
$ sudo nano /var/hg/hgweb.config
208 1 Dimitry Profus
209 1 Dimitry Profus
Add the following and save
210 1 Dimitry Profus
211 1 Dimitry Profus
[paths]
212 12 Dimitry Profus
/=/var/hg/repos/**
213 1 Dimitry Profus
214 1 Dimitry Profus
[web]
215 1 Dimitry Profus
allow_push = *
216 1 Dimitry Profus
push_ssl = false
217 1 Dimitry Profus
allowbz2 = yes
218 1 Dimitry Profus
allowgz = yes
219 1 Dimitry Profus
allowzip = yes
220 1 Dimitry Profus
</pre>
221 1 Dimitry Profus
# Setup permissions
222 1 Dimitry Profus
<pre>
223 12 Dimitry Profus
$ sudo chown -R www-data:www-data /var/hg
224 12 Dimitry Profus
$ sudo chmod gu+x /var/hg/hgwebdir.cgi
225 1 Dimitry Profus
</pre>
226 1 Dimitry Profus
# Create a Apache config file
227 1 Dimitry Profus
<pre>
228 1 Dimitry Profus
$ sudo nano /etc/apache2/conf.d/hg.config
229 1 Dimitry Profus
230 1 Dimitry Profus
Add the following and save
231 1 Dimitry Profus
 
232 1 Dimitry Profus
PerlLoadModule Apache::Redmine
233 12 Dimitry Profus
ScriptAlias /hg  "/var/hg/hgwebdir.cgi"
234 1 Dimitry Profus
<Location /hg  >
235 1 Dimitry Profus
	AuthType Basic
236 13 Dimitry Profus
	AuthName "Redmine Mercurial Repository" 
237 1 Dimitry Profus
	Require valid-user
238 1 Dimitry Profus
239 1 Dimitry Profus
	#Redmine auth
240 1 Dimitry Profus
	PerlAccessHandler Apache::Authn::Redmine::access_handler
241 1 Dimitry Profus
	PerlAuthenHandler Apache::Authn::Redmine::authen_handler
242 1 Dimitry Profus
	RedmineDSN "DBI:mysql:database=redmine;host=localhost" 
243 1 Dimitry Profus
	RedmineDbUser "redmine" 
244 1 Dimitry Profus
	RedmineDbPass "password" 
245 1 Dimitry Profus
</Location>
246 1 Dimitry Profus
</pre>
247 1 Dimitry Profus
# Add a symbolic link to Redmine.pm
248 1 Dimitry Profus
<pre>
249 1 Dimitry Profus
$ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache/Redmine.pm
250 1 Dimitry Profus
$ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache2/Redmine.pm  
251 1 Dimitry Profus
</pre>
252 1 Dimitry Profus
# Enable the required Apache modules and restart Apache
253 1 Dimitry Profus
<pre>
254 1 Dimitry Profus
$ sudo /etc/init.d/apache2 restart
255 1 Dimitry Profus
</pre>
256 1 Dimitry Profus
# Create a new test repository and project in Redmine
257 1 Dimitry Profus
<pre>
258 12 Dimitry Profus
$ sudo hg init /var/hg/repos/test
259 12 Dimitry Profus
$ sudo chown -R www-data:www-data /var/hg/repos/test
260 1 Dimitry Profus
261 1 Dimitry Profus
Create a new project with and identifier 'test'
262 1 Dimitry Profus
263 1 Dimitry Profus
In the project Settings > Repository set
264 1 Dimitry Profus
SCM: Mercurial
265 12 Dimitry Profus
Path to repository: /var/hg/repos/test
266 1 Dimitry Profus
Press the 'Create' button
267 1 Dimitry Profus
268 1 Dimitry Profus
Goto to the Repository tab of the test project
269 1 Dimitry Profus
</pre>
270 1 Dimitry Profus
# View the test repository in the web browser 
271 1 Dimitry Profus
<pre>
272 1 Dimitry Profus
> http://[my site name]/hg/test
273 1 Dimitry Profus
</pre>
274 1 Dimitry Profus
275 1 Dimitry Profus
h2. Subversion Integration
276 1 Dimitry Profus
277 1 Dimitry Profus
# Install the latest Mercurial release 
278 1 Dimitry Profus
<pre>
279 1 Dimitry Profus
$ sudo apt-get install subversion libapache2-svn libapache-dbi-perl libapache2-mod-perl2
280 1 Dimitry Profus
</pre>
281 1 Dimitry Profus
# Create the svn repository directory
282 1 Dimitry Profus
<pre>
283 12 Dimitry Profus
$ sudo mkdir /var/svn
284 1 Dimitry Profus
</pre>
285 1 Dimitry Profus
# Setup permissions
286 1 Dimitry Profus
<pre>
287 12 Dimitry Profus
$ sudo chown -R www-data:www-data /var/svn
288 1 Dimitry Profus
</pre>
289 1 Dimitry Profus
# Add a symbolic link to Redmine.pm
290 1 Dimitry Profus
<pre>
291 1 Dimitry Profus
$ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache/Redmine.pm
292 1 Dimitry Profus
$ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache2/Redmine.pm  
293 1 Dimitry Profus
</pre>
294 1 Dimitry Profus
# Create a Apache config file
295 1 Dimitry Profus
<pre>
296 1 Dimitry Profus
$ sudo nano /etc/apache2/conf.d/svn.config
297 1 Dimitry Profus
</pre>
298 1 Dimitry Profus
Add the following and save
299 1 Dimitry Profus
<pre>
300 16 Dimitry Profus
PerlLoadModule Apache::Redmine
301 16 Dimitry Profus
<Location /svn>
302 16 Dimitry Profus
	DAV svn
303 16 Dimitry Profus
	SVNParentPath "/var/svn" 
304 16 Dimitry Profus
	Order deny,allow
305 16 Dimitry Profus
	Deny from all
306 16 Dimitry Profus
	Satisfy any
307 1 Dimitry Profus
308 16 Dimitry Profus
	PerlAccessHandler Apache::Authn::Redmine::access_handler
309 16 Dimitry Profus
	PerlAuthenHandler Apache::Authn::Redmine::authen_handler
310 16 Dimitry Profus
	AuthType Basic
311 16 Dimitry Profus
	AuthName "Redmine Subversion Repository" 
312 1 Dimitry Profus
313 16 Dimitry Profus
	#read-only access    
314 16 Dimitry Profus
	<Limit GET PROPFIND OPTIONS REPORT>
315 16 Dimitry Profus
		Require valid-user
316 16 Dimitry Profus
		Allow from [my server ip]
317 16 Dimitry Profus
		# Allow from another-ip
318 16 Dimitry Profus
		 Satisfy any
319 16 Dimitry Profus
	</Limit>
320 16 Dimitry Profus
		# write access
321 16 Dimitry Profus
		<LimitExcept GET PROPFIND OPTIONS REPORT>
322 16 Dimitry Profus
		Require valid-user
323 16 Dimitry Profus
	</LimitExcept>
324 1 Dimitry Profus
325 16 Dimitry Profus
	## for mysql
326 16 Dimitry Profus
	RedmineDSN "DBI:mysql:database=redmine;host=localhost" 
327 16 Dimitry Profus
	RedmineDbUser "redmine" 
328 16 Dimitry Profus
	RedmineDbPass "password" 
329 16 Dimitry Profus
</Location>
330 1 Dimitry Profus
</pre>
331 1 Dimitry Profus
# Enable the required Apache modules and restart Apache
332 1 Dimitry Profus
<pre>
333 1 Dimitry Profus
$ sudo a2enmod dav_svn
334 1 Dimitry Profus
$ sudo /etc/init.d/apache2 restart
335 1 Dimitry Profus
</pre>
336 1 Dimitry Profus
# Create a new test repository
337 1 Dimitry Profus
<pre>
338 12 Dimitry Profus
$ sudo svnadmin create /var/svn/test
339 12 Dimitry Profus
$ sudo chown -R www-data:www-data /var/svn/test
340 1 Dimitry Profus
</pre>
341 1 Dimitry Profus
342 7 Dimitry Profus
h2. Automate Repository Creation
343 5 Dimitry Profus
344 3 Dimitry Profus
# Enable WS for repository management and generate and API key
345 3 Dimitry Profus
<pre>
346 3 Dimitry Profus
* From the Redmine Administration menu select Settings
347 3 Dimitry Profus
* Click on the Repositories tab
348 3 Dimitry Profus
* Enable the 'Enable WS for repository management' checkbox
349 3 Dimitry Profus
* Click the 'Generate a key' link 
350 3 Dimitry Profus
* Press the 'Save' button
351 3 Dimitry Profus
</pre>
352 3 Dimitry Profus
# Modify reposman.rb
353 3 Dimitry Profus
<pre>
354 3 Dimitry Profus
$ sudo nano /usr/share/extra/svn/reposman.rb
355 3 Dimitry Profus
356 3 Dimitry Profus
Add the following to module SCM and save  
357 3 Dimitry Profus
358 3 Dimitry Profus
  module Mercurial
359 3 Dimitry Profus
    def self.create(path)
360 3 Dimitry Profus
      Dir.mkdir path
361 3 Dimitry Profus
      Dir.chdir(path) do
362 3 Dimitry Profus
        system_or_raise "hg init"
363 3 Dimitry Profus
      end
364 3 Dimitry Profus
    end
365 3 Dimitry Profus
  end
366 3 Dimitry Profus
</pre>
367 6 Dimitry Profus
# Schedule the reposman.rb script to run every minute
368 3 Dimitry Profus
<pre>
369 3 Dimitry Profus
$ sudo nano /etc/cron.d/redmine
370 7 Dimitry Profus
</pre>
371 9 Dimitry Profus
Add one of the following lines (not both) and save.
372 1 Dimitry Profus
(Note: you will need to replace [my API key]  with the API key you generated in step 1) 
373 7 Dimitry Profus
.
374 11 Dimitry Profus
To create subversion repositories add:
375 7 Dimitry Profus
<pre>
376 14 Dimitry Profus
* * * * * root ruby /usr/share/redmine/extra/svn/reposman.rb --redmine localhost/redmine --scm Subversion --svn-dir /var/hg/repos --owner www-data --url file:///var/svn --key=[my API key] >> /var/log/reposman.log
377 7 Dimitry Profus
</pre>
378 11 Dimitry Profus
OR to create Mecurial repositories add:
379 8 Dimitry Profus
<pre>
380 14 Dimitry Profus
* * * * * root ruby /usr/share/redmine/extra/svn/reposman.rb --redmine localhost/redmine --scm Mercurial --svn-dir /var/hg/repos --owner www-data --url /var/hg/repos --key=[my API key] >> /var/log/reposman.log
381 1 Dimitry Profus
</pre>
382 5 Dimitry Profus
383 15 Dimitry Profus
h2. Automatic refresh of repositories in Redmine
384 15 Dimitry Profus
385 15 Dimitry Profus
# Schedule the fetch_changesets script to run every 15 minutes
386 15 Dimitry Profus
<pre>
387 17 Dimitry Profus
$ sudo nano /var/cron.d/redmine
388 17 Dimitry Profus
389 17 Dimitry Profus
Add the following line and save
390 17 Dimitry Profus
391 15 Dimitry Profus
*/15 * * * * root ruby /usr/share/redmine/script/runner "Repository.fetch_changesets" -e production > /dev/null 2>&1
392 15 Dimitry Profus
</pre>
393 16 Dimitry Profus
# Setup a changegroup script on the Mercurial server to run fetch_changesets after each push to a Mercurial repository 
394 15 Dimitry Profus
<pre>
395 15 Dimitry Profus
$ sudo nano /var/hg/changegroup-hook
396 15 Dimitry Profus
</pre>
397 15 Dimitry Profus
Add the following text and save
398 15 Dimitry Profus
(Note: you will need to replace [your API key] the API key you generated in Redmine
399 15 Dimitry Profus
<pre>
400 15 Dimitry Profus
#!/bin/sh
401 15 Dimitry Profus
curl "http://localhost/redmine/sys/fetch_changesets?key=[your API key]"  > /dev/null 2>&1
402 15 Dimitry Profus
</pre>
403 15 Dimitry Profus
Setup permissions
404 15 Dimitry Profus
<pre>
405 15 Dimitry Profus
$ sudo chown www-data:www-data /var/hg/changegroup-hook
406 15 Dimitry Profus
$ sudo chmod ug+x /var/hg/changegroup-hook
407 15 Dimitry Profus
</pre>
408 15 Dimitry Profus
Modify the hgweb.config file
409 15 Dimitry Profus
<pre>
410 15 Dimitry Profus
$ sudo nano /var/hg/hgweb.config
411 15 Dimitry Profus
</pre>
412 15 Dimitry Profus
Add the following section and save
413 15 Dimitry Profus
<pre>
414 15 Dimitry Profus
[hooks]
415 15 Dimitry Profus
changegroup = /var/hg/changegroup-hook
416 15 Dimitry Profus
</pre>
417 15 Dimitry Profus
418 1 Dimitry Profus
h2. Email Integration
419 1 Dimitry Profus
420 1 Dimitry Profus
# Install and configure Sendmail
421 1 Dimitry Profus
<pre>
422 1 Dimitry Profus
$ sudo apt-get install sendmail
423 1 Dimitry Profus
$ sudo sendmailconfig
424 1 Dimitry Profus
425 1 Dimitry Profus
(Answer Yes to all questions which you will be asked)
426 1 Dimitry Profus
</pre>
427 1 Dimitry Profus
# Update the Redmine configuration file
428 1 Dimitry Profus
<pre>
429 1 Dimitry Profus
$ sudo nano /usr/share/redmine/config/configuration.yml
430 1 Dimitry Profus
431 1 Dimitry Profus
Add the following text and save
432 1 Dimitry Profus
433 1 Dimitry Profus
 production:
434 1 Dimitry Profus
   email_delivery:
435 1 Dimitry Profus
     delivery_method: :sendmail
436 1 Dimitry Profus
</pre>
437 18 Dimitry Profus
438 23 Dimitry Profus
h2. Backup to Amazon S3 cloud storage
439 18 Dimitry Profus
440 22 Dimitry Profus
# Create an account at http://aws.amazon.com/ 
441 18 Dimitry Profus
# Create a S3 bucket using the aws management console https://console.aws.amazon.com/ec2/home
442 21 Dimitry Profus
# View your Access Keys at https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key
443 18 Dimitry Profus
# Build and install fuse to 2.8.4
444 18 Dimitry Profus
<pre>
445 18 Dimitry Profus
$ sudo wget https://launchpad.net/ubuntu/+archive/primary/+files/fuse_2.8.4.orig.tar.gz
446 18 Dimitry Profus
$ cd fuse-2.8.4/
447 18 Dimitry Profus
$ tar xzf fuse_2.8.4.orig.tar.gz 
448 18 Dimitry Profus
$ sudo ./configure 
449 18 Dimitry Profus
$ sudo make
450 18 Dimitry Profus
$ sudo make install
451 18 Dimitry Profus
</pre>
452 18 Dimitry Profus
# Build and install s3fs 1.61 
453 18 Dimitry Profus
<pre>
454 18 Dimitry Profus
$ sudo apt-get install libxml2-dev
455 18 Dimitry Profus
$ wget http://s3fs.googlecode.com/files/s3fs-1.61.tar.gz
456 18 Dimitry Profus
$ tar xzf s3fs-1.61.tar.gz 
457 18 Dimitry Profus
$ cd s3fs-1.61/
458 18 Dimitry Profus
$ sudo ./configure 
459 18 Dimitry Profus
$ sudo make
460 18 Dimitry Profus
$ sudo make install
461 18 Dimitry Profus
</pre>
462 18 Dimitry Profus
# Setup s3fs password file
463 18 Dimitry Profus
<pre>
464 18 Dimitry Profus
$ sudo nano /etc/passwd-s3fs
465 18 Dimitry Profus
</pre>
466 24 Dimitry Profus
Added your 'Access Key ID' and 'Secret Access Key' separated by a colon
467 24 Dimitry Profus
<pre>
468 18 Dimitry Profus
[accessKeyId]:[secretAccessKey]
469 18 Dimitry Profus
</pre>
470 18 Dimitry Profus
Setup permissions
471 18 Dimitry Profus
<pre>
472 18 Dimitry Profus
sudo chmod 650 /etc/passwd-s3fs
473 18 Dimitry Profus
</pre> 
474 18 Dimitry Profus
# Create mounting point
475 18 Dimitry Profus
<pre>
476 18 Dimitry Profus
$ sudo mkdir /mnt/s3
477 18 Dimitry Profus
</pre>
478 25 Dimitry Profus
# Mount your S3 bucket
479 18 Dimitry Profus
<pre>
480 18 Dimitry Profus
$ sudo s3fs [your-s3-bucket-name] /mnt/s3 -ouse_cache=/tmp -o allow_other
481 18 Dimitry Profus
</pre>
482 18 Dimitry Profus
# Test it worked
483 18 Dimitry Profus
<pre>
484 18 Dimitry Profus
$ echo hello > welcome.txt
485 18 Dimitry Profus
$ ls /mnt/s3
486 18 Dimitry Profus
</pre>
487 18 Dimitry Profus
# Create upstart job to mount the s3 file system start up
488 18 Dimitry Profus
<pre>
489 18 Dimitry Profus
$ sudo nano /etc/init/s3.conf
490 18 Dimitry Profus
</pre>
491 18 Dimitry Profus
Add the following text and save.
492 18 Dimitry Profus
<pre>
493 18 Dimitry Profus
description "Mount Amazon S3 file system and on system start"
494 18 Dimitry Profus
495 18 Dimitry Profus
start on (local-filesystems and net-device-up IFACE!=lo)
496 18 Dimitry Profus
stop on runlevel [016]
497 18 Dimitry Profus
498 18 Dimitry Profus
respawn
499 18 Dimitry Profus
500 18 Dimitry Profus
exec s3fs -f [your-s3-bucket-name] /mnt/s3 -ouse_cache=/tmp -o allow_other
501 18 Dimitry Profus
</pre>
502 19 Dimitry Profus
# Create the backup script file
503 19 Dimitry Profus
<pre>
504 27 Dimitry Profus
$ sudo apt-get install mailutils
505 19 Dimitry Profus
$ sudo nano /usr/local/bin/backup-redmine
506 29 Dimitry Profus
</pre>
507 19 Dimitry Profus
Add the following text and save.
508 29 Dimitry Profus
<pre>
509 19 Dimitry Profus
#!/bin/bash
510 19 Dimitry Profus
####################################
511 19 Dimitry Profus
#
512 30 Dimitry Profus
# Backup Redmine to S3 mount script with
513 19 Dimitry Profus
# grandfather-father-son rotation.
514 19 Dimitry Profus
#
515 1 Dimitry Profus
####################################
516 1 Dimitry Profus
517 29 Dimitry Profus
# Email Address to send error mail to? 
518 30 Dimitry Profus
admin_email_address="user@domain.com"
519 29 Dimitry Profus
520 1 Dimitry Profus
# What to backup. 
521 30 Dimitry Profus
backup_files="/var/redmine-database-backup /usr/share/redmine/files /var/hg /var/svn /etc/apache2/conf.d /etc/apache2/sites-available" 
522 1 Dimitry Profus
523 1 Dimitry Profus
# Where to backup to.
524 1 Dimitry Profus
dest="/mnt/s3"
525 1 Dimitry Profus
526 26 Dimitry Profus
# logging
527 26 Dimitry Profus
error_log=/var/log/backup-redmine.log
528 26 Dimitry Profus
529 26 Dimitry Profus
# Remove previous log file
530 26 Dimitry Profus
if [ -e "$error_log" ]
531 26 Dimitry Profus
then
532 26 Dimitry Profus
rm -f $error_log
533 26 Dimitry Profus
fi
534 26 Dimitry Profus
535 26 Dimitry Profus
# IO redirection for logging.
536 26 Dimitry Profus
touch $error_log
537 26 Dimitry Profus
exec 2> $error_log
538 26 Dimitry Profus
539 26 Dimitry Profus
#  Create required directories
540 26 Dimitry Profus
if [ ! -e "/var/redmine-database-backup" ] 
541 26 Dimitry Profus
then
542 26 Dimitry Profus
mkdir "/var/redmine-database-backup"
543 26 Dimitry Profus
fi
544 26 Dimitry Profus
545 26 Dimitry Profus
# Dump the redmine database
546 26 Dimitry Profus
mysqldump --user=redmine --password=password --single-transaction redmine > /var/redmine-database-backup/redmine-db-dump.sql
547 26 Dimitry Profus
548 19 Dimitry Profus
# Setup variables for the archive filename.
549 19 Dimitry Profus
day=$(date +%A)
550 19 Dimitry Profus
hostname=$(hostname -s)
551 19 Dimitry Profus
552 19 Dimitry Profus
# Find which week of the month 1-4 it is.
553 19 Dimitry Profus
day_num=$(date +%d)
554 19 Dimitry Profus
if (( $day_num <= 7 )); then
555 19 Dimitry Profus
        week_file="$hostname-week1.tgz"
556 19 Dimitry Profus
elif (( $day_num > 7 && $day_num <= 14 )); then
557 19 Dimitry Profus
        week_file="$hostname-week2.tgz"
558 19 Dimitry Profus
elif (( $day_num > 14 && $day_num <= 21 )); then
559 19 Dimitry Profus
        week_file="$hostname-week3.tgz"
560 19 Dimitry Profus
elif (( $day_num > 21 && $day_num < 32 )); then
561 19 Dimitry Profus
        week_file="$hostname-week4.tgz"
562 19 Dimitry Profus
fi
563 19 Dimitry Profus
564 19 Dimitry Profus
# Find if the Month is odd or even.
565 19 Dimitry Profus
month_num=$(date +%m)
566 19 Dimitry Profus
month=$(expr $month_num % 2)
567 19 Dimitry Profus
if [ $month -eq 0 ]; then
568 1 Dimitry Profus
        month_file="$hostname-month2.tgz"
569 19 Dimitry Profus
else
570 19 Dimitry Profus
        month_file="$hostname-month1.tgz"
571 1 Dimitry Profus
fi
572 1 Dimitry Profus
573 1 Dimitry Profus
# Create archive filename.
574 1 Dimitry Profus
if [ $day_num == 1 ]; then
575 26 Dimitry Profus
	archive_file=$month_file
576 1 Dimitry Profus
elif [ $day != "Saturday" ]; then
577 1 Dimitry Profus
        archive_file="$hostname-$day.tgz"
578 28 Dimitry Profus
else 
579 1 Dimitry Profus
	archive_file=$week_file
580 28 Dimitry Profus
fi
581 1 Dimitry Profus
582 1 Dimitry Profus
# Backup the files using tar.
583 1 Dimitry Profus
if mount | grep -q "$dest"
584 1 Dimitry Profus
then
585 1 Dimitry Profus
tar czfP $dest/$archive_file $backup_files
586 26 Dimitry Profus
else
587 29 Dimitry Profus
echo "backup destination $dest is not mounted" >&2
588 26 Dimitry Profus
fi
589 26 Dimitry Profus
590 29 Dimitry Profus
# Restore IO output
591 31 Dimitry Profus
exec 2>&1
592 26 Dimitry Profus
593 29 Dimitry Profus
# Check for errors
594 26 Dimitry Profus
if [ -s "$error_log" ]
595 26 Dimitry Profus
then
596 29 Dimitry Profus
echo "#### Backup Failed ####"
597 29 Dimitry Profus
cat "$error_log" 
598 29 Dimitry Profus
cat "$error_log" | mail -s "Redmine backup failed!"  $admin_email_address 
599 19 Dimitry Profus
fi
600 1 Dimitry Profus
601 31 Dimitry Profus
# Clean up
602 31 Dimitry Profus
if [ -e "$error_log" ]
603 31 Dimitry Profus
then
604 31 Dimitry Profus
rm -f $error_log
605 31 Dimitry Profus
fi
606 19 Dimitry Profus
</pre>
607 19 Dimitry Profus
# Setup permissions 
608 19 Dimitry Profus
<pre>
609 19 Dimitry Profus
sudo chmod ug+x /usr/local/bin/backup-redmine
610 19 Dimitry Profus
</pre>
611 19 Dimitry Profus
# Schedule the backup to run once a day at 12am
612 19 Dimitry Profus
<pre>
613 19 Dimitry Profus
$ sudo nano /etc/cron.d/redmine
614 19 Dimitry Profus
615 19 Dimitry Profus
Add the following line and save
616 19 Dimitry Profus
617 19 Dimitry Profus
0 0 * * * root /usr/local/bin/backup-redmine
618 19 Dimitry Profus
</pre>
619 20 Dimitry Profus
# Test the script
620 20 Dimitry Profus
<pre>
621 20 Dimitry Profus
$ sudo backup-redmine
622 20 Dimitry Profus
</pre>