Skip to content

Instantly share code, notes, and snippets.

@nvurgaft
Created January 30, 2018 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nvurgaft/7255a3748e0469e4faaaa9347d9f0676 to your computer and use it in GitHub Desktop.
Save nvurgaft/7255a3748e0469e4faaaa9347d9f0676 to your computer and use it in GitHub Desktop.
Runs a barebone Redmine installation as a Windows service and opens it to the outside on port 3000
REDMINE_DIR = 'C:\redmine\redmine-3.4.4\redmine-3.4.4'
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 'ruby bin/rails s -b 0.0.0.0 -e production', :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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment