Redmine: Difference between revisions

From Alpine Linux
No edit summary
(replace /etc/init.d with rc-service)
 
(42 intermediate revisions by 10 users not shown)
Line 1: Line 1:
''Note:'' We need to install using the edge repositories.
{{Draft}}


Change to the edge repository:
NOTE: all of this page are out of wync, new packages are ruby-unicorn that includes a redmine example file..


mv /etc/apk/repositories /etc/apk/repositories.old
NOTE: Alpine 2.5+ installations need to follow installation instructions for version 2.1.2 at the bottom of this page.
echo -e "http://dl-3.alpinelinux.org/alpine/edge/main/" >> /etc/apk/repositories


Update and upgrade
NOTE: This is a complete rewrite of our Redmine install how-to. Previously, Ruby packages needed by Redmine needed to be installed manually with rubygems. Now we have Ruby packages needed for Remine in our repository. As of writing, ruby packages are maintained in testing repository.


apk -U upgrade
=Some assumptions=


Install services
* For this how-to we assume you are running an Hard-disk install of Alpine Linux. If you are running from RAM, please make sure you use LBU.
{{:Setting Up Lighttpd With FastCGI}}
* Alpine Linux uses Lighttpd as default web-server. Redmine will be running with FastCGI inside Lighttpd. If you like to install Redmine with any other web-server, you will need to install it manually. Which are currently: ruby-rails ruby-fcgi ruby-rmagick ruby-i18n ruby-openid rubygems
Install extra packages:
* We are using MySQL as database for our Redmine install. Redmine is also able to run with PostgreSQL or SQLite.
apk add fcgi mysql mysql-dev rubygems
* MySQL is running on a remote location. Please follow other tutorials on how to setup MySQL.  (need link).
* Detailed information regarding Redmine installation can be found: https://www.redmine.org/projects/redmine/wiki/RedmineInstall


Install the following rubygems (gem install <gemname> --version <version>).  Note: newer versions of the gems may work, but these have been confirmed working in Alpine 2.1.2:
actionmailer (2.3.3)
actionpack (2.3.3)
activerecord (2.3.3)
activeresource (2.3.3)
activesupport (2.3.3)
edavis10-object_daddy (0.4.3)
fcgi (0.8.8)
mocha (0.9.10)
mysql (2.8.1)
rack (1.0.1)
rails (2.3.3)
rake (0.8.7)
shoulda (2.10.3)
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3)


Configure MySql
=Installing Redmine=


/usr/bin/mysql_install_db --user=mysql
{{Cmd|apk add redmine}}
/etc/init.d/mysql start && rc-update add mysql default
/usr/bin/mysqladmin -u root password 'password'


Create the redmine database
On a Alpine base install this should pull in approximately 50 packages including (almost) all Ruby dependencies and Lighttpd. If you like to run a different webserver, you will need to skip redmine package and install all deps manually with apk.


mysql -u root -p
=Database support=
Redmine supports various database backends. Here we will only cover MySQL and PostgreSQL.


create database redmine character set utf8;
== Option 1 - MySQL ==
grant all privileges on redmine.* to 'redmine'@'localhost' identified by 'Secur3P@ass';
For Redmine to communicate with MySQL server we will need to have the mysql ruby package. (if you want to run another db, just install the appropriate db package).
flush privileges;
exit


Create redmine folder
{{Cmd|apk add ruby-mysql}}


mkdir -p /usr/share/webapps/redmine
Now before we continue we need to prepare our database. According [https://www.redmine.org/projects/redmine/wiki/RedmineInstall Redmine website] you need to do the following:


Download, unpack and move Redmine
{{Cmd|create database redmine character set utf8;
create user 'redmine'@'localhost' identified by 'my_password';
grant all privileges on redmine.* to 'redmine'@'localhost';}}


cd /tmp/
If you need mysql client, you can install it like this:
wget http://rubyforge.org/frs/download.php/73140/redmine-1.0.3.tar.gz
tar zxvf redmine-1.0.3.tar.gz
mv redmine-1.0.3/* /usr/share/webapps/redmine/


Change permissions
{{Cmd|apk add mysql-client}}


chown -R lighttpd:lighttpd /usr/share/webapps/redmine
You can of course also use a tool like phpmyadmin to create the database and setup the user.


Edit the database config file and put the mysql password
== Option 2 - PostgreSQL ==
{{Cmd|apk add ruby-pg postgresql}}


cp /usr/share/webapps/redmine/config/database.yml.example /usr/share/webapps/redmine/config/database.yml
Initialize and start database engine:
nano /usr/share/webapps/redmine/config/database.yml
{{Cmd|rc-service postgresql setup
rc-service postgresql start}}


Some more steps
Create redmine db user, replacing 'redminepw' with your own password:
{{Cmd|psql -U postgres -c "CREATE ROLE redmine LOGIN ENCRYPTED PASSWORD 'redminepw' NOINHERIT VALID UNTIL 'infinity';"}}


cd /usr/share/webapps/redmine
Create the redmine database (note that you need template0 for UTF8):
mv public/dispatch.fcgi.example public/dispatch.fcgi
{{Cmd|<nowiki>psql -U postgres -c "CREATE DATABASE redmine WITH ENCODING 'UTF8' OWNER=redmine TEMPLATE = template0;"</nowiki>}}


rake generate_session_store
=Redmine config files=
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake redmine:load_default_data


Note: keep default language of '''en'''
Redmine default config files are located inside /etc/redmine. For Redmine to find your database, please edit database.yml. We have removed all entries accept the default production one. For examples please check: /var/www/localhost/htdocs/redmine/config
If you need to edit additional configuration files, please move them to /etc/redmine and link them back to the original location. This way apk will use config protect and not overwrite your config files on update. Don't forget to edit the other files, like your SMTP configuration in configuration.yml.


Start the Redmine testing webserver
First we need to generate a session store secret:


  ruby /usr/share/webapps/redmine/script/server webrick -e production
  su -pc "cd /var/www/localhost/htdocs/redmine; /usr/lib/ruby/gems/1.8/bin/rake generate_session_store" lighttpd


Now you can browse to '''localhost:3000''' an log using '''admin''' user and '''admin''' password.
Now we populate the database:


Once Redmine is confirmed working, kill webrick. Then setup lighttpd by editing lighttpd.conf:
  su -pc "cd /var/www/localhost/htdocs/redmine; RAILS_ENV=production /usr/lib/ruby/gems/1.8/bin/rake db:migrate" lighttpd
$HTTP["url"] =~ "^/redmine/" {
  alias.url = ("/redmine" => "/usr/share/webapps/redmine/public")
  server.document-root = "/usr/share/webapps/redmine/public/"
  server.error-handler-404 = "/redmine/dispatch.fcgi"
  index-file.names        = ("dispatch.fcgi")
  # Change *-procs to 2 if you need to use Upload Progress or other tasks that
  # *need* to execute a second request while the first is still pending.
  fastcgi.server          += (
        ".fcgi" => (
                "localhost" => (
                        "min-procs"      => 1,
                        "max-procs"      => 2,
                        "check-local"    => "disable",
                        "socket"          => "/var/run/redmine/fcgi.socket",
                        "bin-path"        => "/usr/bin/ruby /usr/share/webapps/redmine/public/dispatch.fcgi",
                        "bin-environment" => (
                                "RAILS_ENV"              => "production"
                        )
                )
        )
  )
}


Restart lighttpd
=Setup Lighttpd=
  /etc/init.d/lighttpd restart
 
Now our database is ready, we need to configure Lighttpd. We have included an example Redmine/Ligghtpd configuration based on FastCGI. You can find it in /etc/lighttpd.
When you are finished setting up Ligghtpd configuation include it inside lighttpd.conf and we can start it.
 
{{Cmd|vi /etc/lighttpd/redmine-virtual.conf}}
 
{{Cmd|vi /etc/lighttpd/lighttpd.conf}}
 
  ...
  include "redmine-virtual.conf"
  ...
 
{{Cmd|rc-service lighttpd start}}
 
If your server does not run, you can find information in /var/log/lighttpd. If that does not provide a clue you can also run Lighttpd in foreground. It should display some more debug information.
 
{{Cmd|rc-service lighttpd stop
lighttpd -f /etc/lighttpd/lighttpd.conf -D}}
 
= Enabling Email to Ticket =
''Note:'' This configuration is not very secure in that it uses out of the box postfix configuration.  It's assumed that additional configuration will be applied to postfix, but that is outside of the scope of this section.
 
First, add postfix.
{{Cmd|apk add postfix}}
Add aliases to /etc/postfix/aliases (replace url with your URL and InsertKeyHere with your Redmine key):
test: "|ruby /var/www/localhost/htdocs/redmine/extra/mail_handler/rdm-mailhandler.rb --url https://bugs.alpinelinux.org --key InsertKeyHere --project=test --unknown-user=accept --no-permission-check"
Create aliases db
newaliases
Start Postfix
rc-service postfix start
rc-update add postfix
 
=Optional: Enable Email to Ticket for Unknown Users=
Note: To enable email to ticket creation from unknown users/email addresses (after allowing anonymous issue creation within Redmine UI) for the 'myproject' project in Redmine, create the following script and have your email server pipe new emails to this script:
 
  #!/usr/bin/perl
  # Author: Jeff Bilyk
  # March 2, 2011
  #Script to take email from stdin, then:
  # - Check redmine database to see if the user exists
  #  - If user doesn't exist, create the user
  # - Pass the email on the redmine utility:
  #  - echo "email contents" | rake redmine:email:read RAILS_ENV="production" project=myproject
 
  use strict;
  use DBI;
  # global variables
  my $DbName = 'redmine';
  my $DbUser = 'redmine';
  my $DbPassword = 'Secur3P@ass';
  my @fields;
  my @address;
  my $existinguser;
 
  # Get email from stdin
  my @email = <STDIN>;
 
  # Parse field for "for"
  foreach (@email)
  {
  if ($_ =~ /From/)
  {
  @fields = (split /</,$_);
  @address = (split />/,$fields[1]);
  }
  }
 
  my $dbh = DBI->connect('dbi:mysql:' . $DbName, $DbUser, $DbPassword, { PrintError => 0 }) or die "SQL Connect Error:" . DBI->errstr;
 
  # Find out if there're any existing users with the specified email address
  my $sqlStatement = "SELECT * from users where mail = '$address[0]';";
 
  my $sqlCommand = $dbh->prepare($sqlStatement);
 
  $sqlCommand->execute or die "SQL Error: " . DBI->errstr;
 
  my @sqlRecordset;
  $existinguser = 'maybe';
 
  @sqlRecordset = $sqlCommand->fetchrow_array;
 
  if ($sqlRecordset[0] == '') {
  printf "@sqlRecordset \n";
  $existinguser = 'no';
  }
  else {
  $existinguser = 'yes';
  }
 
  # If there isn't a user already, then create one
  if ($existinguser == 'no')
  {
  my @name = (split /@/,$address[0]);
  printf "Current variables: $name[0]  $address[0]  \n";
  $sqlStatement = "INSERT INTO users (login, firstname, lastname, mail, mail_notification, admin, status, language, type) values (\"$name[0]\", \"$name[0]\", \" \", \"$address[0]\", 0, 0, 1, \"en\", \"User\");";
  $sqlCommand = $dbh->prepare($sqlStatement);
  $sqlCommand->execute or die "SQL Error: " .DBI->errstr;
  printf "User created";
  }
 
  my $timeinsec = `date +%s`;
  open (MYFILE, ">>/var/tmp/$timeinsec");
  print MYFILE "@email";
  close (MYFILE);
 
  system("sed -i 's/^  //' /var/tmp/$timeinsec");
  system("sed -i 's/^ //' /var/tmp/$timeinsec");
 
  `cd /usr/share/webapps/redmine && rake redmine:email:read RAILS_ENV="production" project=myproject < /var/tmp/$timeinsec`;
  exit 0
 
This document is a Work In Progress.
 
[[Category:Server]]
[[Category:Ruby]]
[[Category:SQL]]
[[Category:Programming]]
 
 
=Installing Redmine Since 2.1.2=
 
Redmine in Alpine has switched from lighttpd to unicorn httpd (ruby-fcgi currently has issues and according to redmine devs its the prefered way to run redmine).
 
This basic howto is based on sqlite and has only been tested with sqlite. We need to install the following packages:
 
{{Cmd|apk add ruby-sqlite ruby-unicorn redmine}}
 
Copy the sample config file inside /etc/unicorn
 
{{Cmd|cp /etc/unicorn/redmine.conf.rb.sample /etc/unicorn/redmine.conf.rb}}
 
Edit unicorn conf.d file and set the config file to /etc/unicorn/redmine.conf.rb
 
  {{Cmd|vim /etc/conf.d/unicorn}}
 
Edit redmine database config and set sqlite as database
 
{{Cmd|vim /etc/redmine/database.yml}}
 
Make sure the database directory exists and change owner to redmine
 
{{Cmd|cd /usr/share/webapps/redmine}}
{{Cmd|sudo -u redmine rake generate_secret_token}}
{{Cmd|sudo -u redmine RAILS_ENV&#x3D;production rake db:migrate}}
 
Make sure redmine.conf.rb is correct and run:
 
{{Cmd|rc-service unicorn start}}
 
This will start unicorn httpd and listens on 0.0.0.0:8080 by default.
 
Unicorn is a very basic httpd it is advised to use a reverse proxy in front of it like nginx, pound or any other reverse proxy.
 
Install additional plugins
 
*Copy the plugin directory into the vendor/plugins directory.
 
*Do migration task. (e.g. rake db:migrate_plugins RAILS_ENV=production)
 
*(Re)Start Unicorn.
 
Make sure that the plugin is compatible with your redmine. Installation procedure may vary depending on the plugin.

Latest revision as of 09:57, 17 November 2023

This material is work-in-progress ...

Do not follow instructions here until this notice is removed.
(Last edited by Sertonix on 17 Nov 2023.)

NOTE: all of this page are out of wync, new packages are ruby-unicorn that includes a redmine example file..

NOTE: Alpine 2.5+ installations need to follow installation instructions for version 2.1.2 at the bottom of this page.

NOTE: This is a complete rewrite of our Redmine install how-to. Previously, Ruby packages needed by Redmine needed to be installed manually with rubygems. Now we have Ruby packages needed for Remine in our repository. As of writing, ruby packages are maintained in testing repository.

Some assumptions

  • For this how-to we assume you are running an Hard-disk install of Alpine Linux. If you are running from RAM, please make sure you use LBU.
  • Alpine Linux uses Lighttpd as default web-server. Redmine will be running with FastCGI inside Lighttpd. If you like to install Redmine with any other web-server, you will need to install it manually. Which are currently: ruby-rails ruby-fcgi ruby-rmagick ruby-i18n ruby-openid rubygems
  • We are using MySQL as database for our Redmine install. Redmine is also able to run with PostgreSQL or SQLite.
  • MySQL is running on a remote location. Please follow other tutorials on how to setup MySQL. (need link).
  • Detailed information regarding Redmine installation can be found: https://www.redmine.org/projects/redmine/wiki/RedmineInstall


Installing Redmine

apk add redmine

On a Alpine base install this should pull in approximately 50 packages including (almost) all Ruby dependencies and Lighttpd. If you like to run a different webserver, you will need to skip redmine package and install all deps manually with apk.

Database support

Redmine supports various database backends. Here we will only cover MySQL and PostgreSQL.

Option 1 - MySQL

For Redmine to communicate with MySQL server we will need to have the mysql ruby package. (if you want to run another db, just install the appropriate db package).

apk add ruby-mysql

Now before we continue we need to prepare our database. According Redmine website you need to do the following:

create database redmine character set utf8; create user 'redmine'@'localhost' identified by 'my_password'; grant all privileges on redmine.* to 'redmine'@'localhost';

If you need mysql client, you can install it like this:

apk add mysql-client

You can of course also use a tool like phpmyadmin to create the database and setup the user.

Option 2 - PostgreSQL

apk add ruby-pg postgresql

Initialize and start database engine:

rc-service postgresql setup rc-service postgresql start

Create redmine db user, replacing 'redminepw' with your own password:

psql -U postgres -c "CREATE ROLE redmine LOGIN ENCRYPTED PASSWORD 'redminepw' NOINHERIT VALID UNTIL 'infinity';"

Create the redmine database (note that you need template0 for UTF8):

psql -U postgres -c "CREATE DATABASE redmine WITH ENCODING 'UTF8' OWNER=redmine TEMPLATE = template0;"

Redmine config files

Redmine default config files are located inside /etc/redmine. For Redmine to find your database, please edit database.yml. We have removed all entries accept the default production one. For examples please check: /var/www/localhost/htdocs/redmine/config If you need to edit additional configuration files, please move them to /etc/redmine and link them back to the original location. This way apk will use config protect and not overwrite your config files on update. Don't forget to edit the other files, like your SMTP configuration in configuration.yml.

First we need to generate a session store secret:

su -pc "cd /var/www/localhost/htdocs/redmine; /usr/lib/ruby/gems/1.8/bin/rake generate_session_store" lighttpd

Now we populate the database:

su -pc "cd /var/www/localhost/htdocs/redmine; RAILS_ENV=production /usr/lib/ruby/gems/1.8/bin/rake db:migrate" lighttpd

Setup Lighttpd

Now our database is ready, we need to configure Lighttpd. We have included an example Redmine/Ligghtpd configuration based on FastCGI. You can find it in /etc/lighttpd. When you are finished setting up Ligghtpd configuation include it inside lighttpd.conf and we can start it.

vi /etc/lighttpd/redmine-virtual.conf

vi /etc/lighttpd/lighttpd.conf

 ... 
 include "redmine-virtual.conf"
 ...

rc-service lighttpd start

If your server does not run, you can find information in /var/log/lighttpd. If that does not provide a clue you can also run Lighttpd in foreground. It should display some more debug information.

rc-service lighttpd stop lighttpd -f /etc/lighttpd/lighttpd.conf -D

Enabling Email to Ticket

Note: This configuration is not very secure in that it uses out of the box postfix configuration. It's assumed that additional configuration will be applied to postfix, but that is outside of the scope of this section.

First, add postfix.

apk add postfix

Add aliases to /etc/postfix/aliases (replace url with your URL and InsertKeyHere with your Redmine key):

test: "|ruby /var/www/localhost/htdocs/redmine/extra/mail_handler/rdm-mailhandler.rb --url https://bugs.alpinelinux.org --key InsertKeyHere --project=test --unknown-user=accept --no-permission-check"

Create aliases db

newaliases

Start Postfix

rc-service postfix start
rc-update add postfix

Optional: Enable Email to Ticket for Unknown Users

Note: To enable email to ticket creation from unknown users/email addresses (after allowing anonymous issue creation within Redmine UI) for the 'myproject' project in Redmine, create the following script and have your email server pipe new emails to this script:

 #!/usr/bin/perl
 # Author: Jeff Bilyk
 # March 2, 2011
 #Script to take email from stdin, then:
 # - Check redmine database to see if the user exists
 #   - If user doesn't exist, create the user
 # - Pass the email on the redmine utility:
 #   - echo "email contents" | rake redmine:email:read RAILS_ENV="production" project=myproject
 
 use strict;
 use DBI;
 # global variables
 my $DbName = 'redmine';
 my $DbUser = 'redmine';
 my $DbPassword = 'Secur3P@ass';
 my @fields;
 my @address;
 my $existinguser;
 
 # Get email from stdin
 my @email = <STDIN>;
 
 # Parse field for "for"
 foreach (@email)
 {
 	if ($_ =~ /From/)
 	{
 		@fields = (split /</,$_);
 		@address = (split />/,$fields[1]);
 	}
 }
 
 my $dbh = DBI->connect('dbi:mysql:' . $DbName, $DbUser, $DbPassword, { PrintError => 0 }) or die "SQL Connect Error:" . DBI->errstr;
 
 # Find out if there're any existing users with the specified email address
 my $sqlStatement = "SELECT * from users where mail = '$address[0]';";
 
 my $sqlCommand = $dbh->prepare($sqlStatement);
 
 $sqlCommand->execute or die "SQL Error: " . DBI->errstr;
 
 my @sqlRecordset;
 $existinguser = 'maybe';
 
 @sqlRecordset = $sqlCommand->fetchrow_array;
 
 if ($sqlRecordset[0] == ) {
 	printf "@sqlRecordset \n";
 	$existinguser = 'no';
 }
 else {
 	$existinguser = 'yes';
 }
 
 # If there isn't a user already, then create one
 if ($existinguser == 'no')
 {
 	my @name = (split /@/,$address[0]);
 	printf "Current variables: $name[0]  $address[0]  \n";
 	$sqlStatement = "INSERT INTO users (login, firstname, lastname, mail, mail_notification, admin, status, language, type) values (\"$name[0]\", \"$name[0]\", \" \", \"$address[0]\", 0, 0, 1, \"en\", \"User\");";
 	$sqlCommand = $dbh->prepare($sqlStatement);
 	$sqlCommand->execute or die "SQL Error: " .DBI->errstr;
 	printf "User created";
 }
 
 my $timeinsec = `date +%s`;
 open (MYFILE, ">>/var/tmp/$timeinsec");
 print MYFILE "@email";
 close (MYFILE);
 
 system("sed -i 's/^  //' /var/tmp/$timeinsec");
 system("sed -i 's/^ //' /var/tmp/$timeinsec");
 
 `cd /usr/share/webapps/redmine && rake redmine:email:read RAILS_ENV="production" project=myproject < /var/tmp/$timeinsec`;
 exit 0

This document is a Work In Progress.


Installing Redmine Since 2.1.2

Redmine in Alpine has switched from lighttpd to unicorn httpd (ruby-fcgi currently has issues and according to redmine devs its the prefered way to run redmine).

This basic howto is based on sqlite and has only been tested with sqlite. We need to install the following packages:

apk add ruby-sqlite ruby-unicorn redmine

Copy the sample config file inside /etc/unicorn

cp /etc/unicorn/redmine.conf.rb.sample /etc/unicorn/redmine.conf.rb

Edit unicorn conf.d file and set the config file to /etc/unicorn/redmine.conf.rb

vim /etc/conf.d/unicorn

Edit redmine database config and set sqlite as database

vim /etc/redmine/database.yml

Make sure the database directory exists and change owner to redmine

cd /usr/share/webapps/redmine

sudo -u redmine rake generate_secret_token

sudo -u redmine RAILS_ENV=production rake db:migrate

Make sure redmine.conf.rb is correct and run:

rc-service unicorn start

This will start unicorn httpd and listens on 0.0.0.0:8080 by default.

Unicorn is a very basic httpd it is advised to use a reverse proxy in front of it like nginx, pound or any other reverse proxy.

Install additional plugins

  • Copy the plugin directory into the vendor/plugins directory.
  • Do migration task. (e.g. rake db:migrate_plugins RAILS_ENV=production)
  • (Re)Start Unicorn.

Make sure that the plugin is compatible with your redmine. Installation procedure may vary depending on the plugin.