Set Redmine as Windows service


To setup and run your Redmine installation as a Windows service, open a command prompt and type:

cd C:\Ruby23\bin
gem install win32-service

Under you redmine installation dir (e.g. “C:\My_Redmine”) create a text file named “service.rb” with the following code (in this example our ip address is 192.168.10.1 and the port is 3000; change them according to your environment):

REDMINE_DIR = ‘C:\My_Redmine’
LOG_FILE = “#{REDMINE_DIR}\\log\\service.log”

begin
require ‘win32/daemon’
include Win32

class RedmineService < Daemon

def service_init
File.open(LOG_FILE, ‘a’){ |f| f.puts “Initializing service #{Time.now}” }

@server_pid = Process.spawn ‘c:\Ruby23\bin\rubyw bin/rails s -e production -b 192.168.10.1 -p 3000’, :chdir => REDMINE_DIR, :err => [LOG_FILE, ‘a’] end

def service_main
File.open(LOG_FILE, ‘a’){ |f| f.puts “Service is running #{Time.now} with pid #{@server_pid}” }
while running?
sleep 10
end
end

def service_stop
File.open(LOG_FILE, ‘a’){ |f| f.puts “Stopping server thread #{Time.now}” }
system “taskkill /PID #{@server_pid} /T /F”
Process.waitall
File.open(LOG_FILE, ‘a’){ |f| f.puts “Service stopped #{Time.now}” }
exit!
end
end

RedmineService.mainloop

rescue Exception => e
File.open(LOG_FILE,’a+’){ |f| f.puts ” ***Daemon failure #{Time.now} exception=#{e.inspect}\n#{e.backtrace.join($/)}” }
raise
end

By omitting “-b” parameter, redmine service will be available only on localhost path (i.e. http://localhost:3000).

Now, create the service “Redmine”, running the following command on command prompt:

sc create Redmine binPath= “C:\Ruby23\bin\rubyw -C C:\My_Redmine\ service.rb”

Be careful; there’s a space char after “=” and before “service.rb”.

MISSION ACCOMPLISHED!

Now you can run windows service and login to your redmine application running on the choosen ip address and port (e.g. http://192.168.10.1:3000).

IMPORTANT. Consider that the above procedure is not suitable for production environment. See redmine documents for how to setup redmine service in other ways (e.g. behind an apache/nginx web server).

Leave a comment

Your email address will not be published. Required fields are marked *