HowToInstallRedmineOnUbuntuServer » History » Version 4

Dimitry Profus, 2011-09-23 20:05

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