├── README.md ├── config ├── init.d │ └── redmine ├── nginx │ └── redmine └── redmine │ └── puma.rb.example └── doc └── installation.md /README.md: -------------------------------------------------------------------------------- 1 | running-redmine-on-puma 2 | ======================= 3 | 4 | running redmine on puma [installation](doc/installation.md) tutorial (Ubuntu/MySQL) 5 | 6 | Inspiration from [gitlab installation](https://github.com/gitlabhq/gitlabhq) 7 | -------------------------------------------------------------------------------- /config/init.d/redmine: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # REDMINE 4 | # App Version: 2.3.1 5 | # Ref: https://raw.github.com/gitlabhq/gitlabhq/5-2-stable/lib/support/init.d/gitlab 6 | 7 | ### BEGIN INIT INFO 8 | # Provides: redmine 9 | # Required-Start: $local_fs $remote_fs $network $syslog redis-server 10 | # Required-Stop: $local_fs $remote_fs $network $syslog 11 | # Default-Start: 2 3 4 5 12 | # Default-Stop: 0 1 6 13 | # Short-Description: Redmine project management 14 | # Description: Redmine project management 15 | ### END INIT INFO 16 | 17 | 18 | APP_ROOT="/home/redmine/redmine" 19 | APP_USER="redmine" 20 | DAEMON_OPTS="-C $APP_ROOT/config/puma.rb" 21 | PID_PATH="$APP_ROOT/tmp/pids" 22 | WEB_SERVER_PID="$PID_PATH/puma.pid" 23 | 24 | NAME="redmine" 25 | DESC="Redmine service" 26 | 27 | check_pid(){ 28 | if [ -f $WEB_SERVER_PID ]; then 29 | PID=`cat $WEB_SERVER_PID` 30 | STATUS=`ps aux | grep $PID | grep -v grep | wc -l` 31 | else 32 | STATUS=0 33 | PID=0 34 | fi 35 | } 36 | 37 | execute() { 38 | sudo -u $APP_USER -H bash -l -c "$1" 39 | } 40 | 41 | start() { 42 | cd $APP_ROOT 43 | check_pid 44 | if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then 45 | # Program is running, exit with error code 1. 46 | echo "Error! $DESC $NAME is currently running!" 47 | exit 1 48 | else 49 | if [ `whoami` = root ]; then 50 | execute "RAILS_ENV=production bundle exec puma $DAEMON_OPTS" 51 | echo "$DESC started" 52 | fi 53 | fi 54 | } 55 | 56 | stop() { 57 | cd $APP_ROOT 58 | check_pid 59 | if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then 60 | ## Program is running, stop it. 61 | kill -QUIT `cat $WEB_SERVER_PID` 62 | 63 | rm "$WEB_SERVER_PID" >> /dev/null 64 | echo "$DESC stopped" 65 | else 66 | ## Program is not running, exit with error. 67 | echo "Error! $DESC not started!" 68 | exit 1 69 | fi 70 | } 71 | 72 | restart() { 73 | cd $APP_ROOT 74 | check_pid 75 | if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then 76 | echo "Restarting $DESC..." 77 | kill -USR2 `cat $WEB_SERVER_PID` 78 | echo "$DESC restarted." 79 | else 80 | echo "Error, $NAME not running!" 81 | exit 1 82 | fi 83 | } 84 | 85 | status() { 86 | cd $APP_ROOT 87 | check_pid 88 | if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then 89 | echo "$DESC / Puma with PID $PID is running." 90 | else 91 | echo "$DESC is not running." 92 | exit 1 93 | fi 94 | } 95 | 96 | ## Check to see if we are running as root first. 97 | ## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html 98 | if [ "$(id -u)" != "0" ]; then 99 | echo "This script must be run as root" 100 | exit 1 101 | fi 102 | 103 | case "$1" in 104 | start) 105 | start 106 | ;; 107 | stop) 108 | stop 109 | ;; 110 | restart) 111 | restart 112 | ;; 113 | reload|force-reload) 114 | echo -n "Reloading $NAME configuration: " 115 | kill -HUP `cat $PID` 116 | echo "done." 117 | ;; 118 | status) 119 | status 120 | ;; 121 | *) 122 | echo "Usage: sudo service redmine {start|stop|restart|reload|status}" >&2 123 | exit 1 124 | ;; 125 | esac 126 | 127 | exit 0 128 | -------------------------------------------------------------------------------- /config/nginx/redmine: -------------------------------------------------------------------------------- 1 | # REDMINE 2 | # App Version: 2.3 3 | # Ref: https://raw.github.com/gitlabhq/gitlabhq/5-2-stable/lib/support/nginx/gitlab 4 | 5 | upstream redmine { 6 | server unix:/home/redmine/redmine/tmp/sockets/redmine.socket; 7 | } 8 | 9 | server { 10 | listen YOUR_SERVER_IP:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea 11 | server_name YOUR_SERVER_FQDN; # e.g., server_name source.example.com; 12 | root /home/redmine/redmine/public; 13 | 14 | # individual nginx logs for this redmine vhost 15 | access_log /var/log/nginx/redmine_access.log; 16 | error_log /var/log/nginx/redmine_error.log; 17 | 18 | location / { 19 | # serve static files from defined root folder;. 20 | # @redmine is a named location for the upstream fallback, see below 21 | try_files $uri $uri/index.html $uri.html @redmine; 22 | } 23 | 24 | # if a file, which is not found in the root folder is requested, 25 | # then the proxy pass the request to the upsteam (redmine unicorn) 26 | location @redmine { 27 | proxy_read_timeout 300; # https://github.com/redminehq/redminehq/issues/694 28 | proxy_connect_timeout 300; # https://github.com/redminehq/redminehq/issues/694 29 | proxy_redirect off; 30 | 31 | proxy_set_header X-Forwarded-Proto $scheme; 32 | proxy_set_header Host $http_host; 33 | proxy_set_header X-Real-IP $remote_addr; 34 | 35 | proxy_pass http://redmine; 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /config/redmine/puma.rb.example: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env puma 2 | 3 | # Ref: https://github.com/gitlabhq/gitlabhq/blob/master/config/puma.rb.example 4 | 5 | # Start Puma with next command: 6 | # RAILS_ENV=production bundle exec puma -C ./config/puma.rb 7 | 8 | # uncomment and customize to run in non-root path 9 | # note that config/settings.yml web path should also be changed 10 | # ENV['RAILS_RELATIVE_URL_ROOT'] = "/redmine" 11 | 12 | application_path = '/home/redmine/redmine' 13 | 14 | # The directory to operate out of. 15 | # 16 | # The default is the current directory. 17 | # 18 | directory application_path 19 | 20 | # Set the environment in which the rack's app will run. 21 | # 22 | # The default is “development”. 23 | # 24 | environment 'production' 25 | 26 | # Daemonize the server into the background. Highly suggest that 27 | # this be combined with “pidfile” and “stdout_redirect”. 28 | # 29 | # The default is “false”. 30 | # 31 | daemonize true 32 | 33 | # Store the pid of the server in the file at “path”. 34 | # 35 | pidfile "#{application_path}/tmp/pids/puma.pid" 36 | 37 | # Use “path” as the file to store the server info state. This is 38 | # used by “pumactl” to query and control the server. 39 | # 40 | state_path "#{application_path}/tmp/pids/puma.state" 41 | 42 | # Redirect STDOUT and STDERR to files specified. The 3rd parameter 43 | # (“append”) specifies whether the output is appended, the default is 44 | # “false”. 45 | # 46 | stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log" 47 | # stdout_redirect '/u/apps/lolcat/log/stdout', '/u/apps/lolcat/log/stderr', true 48 | 49 | # Disable request logging. 50 | # 51 | # The default is “false”. 52 | # 53 | # quiet 54 | 55 | # Configure “min” to be the minimum number of threads to use to answer 56 | # requests and “max” the maximum. 57 | # 58 | # The default is “0, 16”. 59 | # 60 | # threads 0, 16 61 | 62 | # Bind the server to “url”. “tcp://”, “unix://” and “ssl://” are the only 63 | # accepted protocols. 64 | # 65 | # The default is “tcp://0.0.0.0:9292”. 66 | # 67 | # bind 'tcp://0.0.0.0:9292' 68 | bind "unix://#{application_path}/tmp/sockets/redmine.socket" 69 | 70 | # Instead of “bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'” you 71 | # can also use the “ssl_bind” option. 72 | # 73 | # ssl_bind '127.0.0.1', '9292', { key: path_to_key, cert: path_to_cert } 74 | 75 | # Code to run before doing a restart. This code should 76 | # close log files, database connections, etc. 77 | # 78 | # This can be called multiple times to add code each time. 79 | # 80 | # on_restart do 81 | # puts 'On restart...' 82 | # end 83 | 84 | # Command to use to restart puma. This should be just how to 85 | # load puma itself (ie. 'ruby -Ilib bin/puma'), not the arguments 86 | # to puma, as those are the same as the original process. 87 | # 88 | # restart_command '/u/app/lolcat/bin/restart_puma' 89 | 90 | # === Cluster mode === 91 | 92 | # How many worker processes to run. 93 | # 94 | # The default is “0”. 95 | # 96 | # workers 2 97 | 98 | # Code to run when a worker boots to setup the process before booting 99 | # the app. 100 | # 101 | # This can be called multiple times to add hooks. 102 | # 103 | # on_worker_boot do 104 | # puts 'On worker boot...' 105 | # end 106 | 107 | # === Puma control rack application === 108 | 109 | # Start the puma control rack application on “url”. This application can 110 | # be communicated with to control the main server. Additionally, you can 111 | # provide an authentication token, so all requests to the control server 112 | # will need to include that token as a query parameter. This allows for 113 | # simple authentication. 114 | # 115 | # Check out https://github.com/puma/puma/blob/master/lib/puma/app/status.rb 116 | # to see what the app has available. 117 | # 118 | # activate_control_app 'unix:///var/run/pumactl.sock' 119 | # activate_control_app 'unix:///var/run/pumactl.sock', { auth_token: '12345' } 120 | # activate_control_app 'unix:///var/run/pumactl.sock', { no_token: true } -------------------------------------------------------------------------------- /doc/installation.md: -------------------------------------------------------------------------------- 1 | # Important notes 2 | 3 | This installation guide was created for and tested on **Debian/Ubuntu** operating systems. 4 | 5 | - - - 6 | 7 | # Overview 8 | 9 | The Redmine installation consists of setting up the following components: 10 | 11 | 1. Packages / Dependencies 12 | 2. Ruby 13 | 3. System Users 14 | 4. Database 15 | 5. Redmine 16 | 6. Nginx 17 | 18 | 19 | # 1. Packages / Dependencies 20 | 21 | Install the required packages: 22 | 23 | sudo apt-get install vim curl git imagemagick libmagickwand-dev 24 | 25 | # 2. Ruby 26 | 27 | Remove old 1.8 ruby if present 28 | 29 | sudo apt-get remove ruby1.8 30 | 31 | Use rvm Install: 32 | 33 | curl -L get.rvm.io | bash -s stable 34 | source ~/.bashrc 35 | source ~/.bash_profile 36 | source ~/.profile 37 | 38 | rvm install 1.9.3 39 | 40 | Install the Bundler Gem: 41 | 42 | sudo gem install bundler 43 | 44 | 45 | # 3. System Users 46 | 47 | Create a `redmine` user for Redmine: 48 | 49 | sudo adduser --disabled-login --gecos 'Redmine' redmine 50 | 51 | 52 | # 4. Database(MySQL) 53 | 54 | # Install the database packages 55 | sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev 56 | 57 | # Login to MySQL 58 | mysql -u root -p 59 | 60 | # Create a user for Redmine. (change $password to a real password) 61 | mysql> CREATE USER 'redmine'@'localhost' IDENTIFIED BY '$password'; 62 | 63 | # Create the Redmine production database 64 | mysql> CREATE DATABASE IF NOT EXISTS `redmine_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; 65 | 66 | # Grant the Redmine user necessary permissions on the table. 67 | mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `redmine_production`.* TO 'redmine'@'localhost'; 68 | 69 | # Quit the database session 70 | mysql> \q 71 | 72 | # Try connecting to the new database with the new user 73 | sudo -u redmine -H mysql -u redmine -p -D redmine_production 74 | 75 | # 5. Redmine 76 | 77 | # We'll install Redmine into home directory of the user "redmine" 78 | cd /home/redmine 79 | sudo su redmine 80 | 81 | ##Use rvm: 82 | 83 | curl -L get.rvm.io | bash -s stable 84 | source ~/.bashrc 85 | source ~/.bash_profile 86 | source ~/.profile 87 | 88 | rvm install 1.9.3 89 | rvm use 1.9.3 --default 90 | 91 | ## Clone the Source 92 | 93 | # Clone Redmine repository 94 | git clone https://github.com/redmine/redmine.git 95 | 96 | # Go to redmine dir 97 | cd /home/redmine/redmine 98 | 99 | # Checkout to stable release 100 | sudo -u redmine -H git checkout 2.3-stable 101 | 102 | **Note:** 103 | You can change `2.3-stable` to `master` if you want the *bleeding edge* version, but 104 | do so with caution! 105 | 106 | ## Configure it 107 | 108 | cd /home/redmine/redmine 109 | 110 | # Make sure Redmine can write to the log/ and tmp/ directories 111 | sudo chown -R redmine log/ 112 | sudo chown -R redmine tmp/ 113 | sudo chmod -R u+rwX log/ 114 | sudo chmod -R u+rwX tmp/ 115 | 116 | # Create directories for sockets/pids and make sure Redmine can write to them 117 | sudo mkdir tmp/pids/ 118 | sudo mkdir tmp/sockets/ 119 | #sudo chown -R redmine plugins 120 | sudo chown -R redmine tmp/pids/ 121 | sudo chown -R redmine tmp/sockets/ 122 | 123 | # Copy the example Puma config 124 | sudo su redmine 125 | curl --output /home/redmine/redmine/config/puma.rb https://raw.github.com/junxy/running-redmine-on-puma/master/config/redmine/puma.rb.example 126 | exit 127 | 128 | **Important Note:** 129 | 130 | 131 | ## Configure Redmine DB settings 132 | 133 | # Mysql 134 | cp config/database.yml.example config/database.yml 135 | vim config/database.yml 136 | # add 137 | socket: /var/run/mysqld/mysqld.sock 138 | reconnect: false 139 | 140 | 141 | Make sure to update username/password in config/database.yml. 142 | 143 | ## Install Gems 144 | 145 | cd /home/redmine/redmine 146 | 147 | # add puma 148 | vim Gemfile 149 | #http://mirrors.tuna.tsinghua.edu.cn/rubygems/ 150 | gem "puma", '~> 2.0.1' 151 | 152 | # For MySQL (note, the option says "without") 153 | bundle install --without development test postgresql sqlite 154 | 155 | ## Session store secret generation 156 | 157 | rake generate_secret_token 158 | 159 | ## Database schema objects creation 160 | 161 | RAILS_ENV=production rake db:migrate 162 | 163 | Database default data set 164 | 165 | RAILS_ENV=production rake redmine:load_default_data 166 | 167 | ## Install Init Script 168 | 169 | Download the init script (will be /etc/init.d/redmine): 170 | 171 | #exit redmine user 172 | exit 173 | 174 | sudo curl --output /etc/init.d/redmine https://raw.github.com/junxy/running-redmine-on-puma/master/config/init.d/redmine 175 | sudo chmod +x /etc/init.d/redmine 176 | 177 | Make Redmine start on boot: 178 | 179 | sudo update-rc.d redmine defaults 22 180 | 181 | ## Test the installation 182 | 183 | ruby script/rails server webrick -e production 184 | 185 | ## Start Your Redmine Instance 186 | 187 | sudo service redmine start 188 | # or 189 | sudo /etc/init.d/redmine restart 190 | 191 | 192 | # 6. Nginx 193 | 194 | **Note:** 195 | If you can't or don't want to use Nginx as your web server, have a look at the 196 | [`Advanced Setup Tips`](./installation.md#advanced-setup-tips) section. 197 | 198 | ## Installation 199 | sudo apt-get install nginx 200 | 201 | ## Site Configuration 202 | 203 | Download an example site config: 204 | 205 | sudo curl --output /etc/nginx/sites-available/redmine https://raw.github.com/junxy/running-redmine-on-puma/master/config/nginx/redmine 206 | sudo ln -s /etc/nginx/sites-available/redmine /etc/nginx/sites-enabled/redmine 207 | 208 | Make sure to edit the config file to match your setup: 209 | 210 | # **YOUR_SERVER_FQDN** to the fully-qualified 211 | # domain name of your host serving Redmine. Also, replace 212 | # the 'listen' line with the following: 213 | # listen 80 default_server; # e.g., listen 192.168.1.1:80; 214 | sudo vim /etc/nginx/sites-available/redmine 215 | 216 | ## Restart 217 | 218 | sudo service nginx restart 219 | 220 | 221 | # Done! 222 | 223 | Visit YOUR_SERVER for your first Redmine login. You can use it to log in: 224 | admin/admin 225 | 226 | **Important Note:** 227 | Please go over to your profile page and immediately change the password, so 228 | nobody can access your Redmine by using this login information later on. 229 | 230 | **Enjoy!** 231 | --------------------------------------------------------------------------------