Restore WIN32 service functionality
Since smart-proxy 1.5, the WIN32 service functionality is broken. To restore it a Gemfile.in must be created or the bundler vs bundler_ext used differently. In addition, the service code removed in commit 038fa6cf7079880b16d998346d05112acefec81e needs to be reintroduced.
#4 Updated by Benjamin Papillon over 6 years ago
To not add too much non dev comments on the pr, here are my findings regarding the tests of this patch.
First, as mchesler found, Ruby 1.9 now uses RUBY_PLATFORM to detect the platform ruby is on. Here is the output frop irb :
irb(main):001:0> puts RUBY_PLATFORM i386-mingw32 => nil irb(main):002:0> puts RUBY_VERSION 1.9.3 => nil
After disabling the checks in register-service.rb, I also commented the following line of register-service.rb because your script is not accepting any argument:
cmd += ' --service'
Last, I had to install 2 gems : "highline" and "win32-service" gems because the registration script depends on them and the gems are not bundled.
The service registration worked fine after that.
Once the service is registered, I tried to start the service. First, I tried to start the service in command line (to check any ruby issues) then from the windows services.
As per registration script, I bypassed the check on PLATFORM to check further.
I had a strange effect with requiring libraries. Here is the irb output of require lines:
C:\AA\foreman\smart\bin>irb <path("../../lib", __FILE__), File.expand_path("../../modules", __FILE__)]) => ["C:/AA/foreman/smart/lib", "C:/AA/foreman/smart/modules", "C:/Ruby193/lib/ru by/site_ruby/1.9.1", "C:/Ruby193/lib/ruby/site_ruby/1.9.1/i386-msvcrt", "C:/Ruby 193/lib/ruby/site_ruby", "C:/Ruby193/lib/ruby/vendor_ruby/1.9.1", "C:/Ruby193/li b/ruby/vendor_ruby/1.9.1/i386-msvcrt", "C:/Ruby193/lib/ruby/vendor_ruby", "C:/Ru by193/lib/ruby/1.9.1", "C:/Ruby193/lib/ruby/1.9.1/i386-mingw32"] irb(main):002:0> require 'smart_proxy' => true irb(main):003:0> require 'win32/daemon' LoadError: cannot load such file -- win32/daemon from (irb):3:in `require' from (irb):3 from C:/Ruby193/bin/irb:12:in `<main>' irb(main):004:0> exit C:\AA\foreman\smart\bin>
If I execute the line
$LOAD_PATH.unshift(*Dir[File.expand_path("../../lib", __FILE__), File.expand_path("../../modules", __FILE__)])before require 'win32/daemon', the daemon library refuse to load. This is strange because code is correct. printing $LOAD_PATH before and after the line shows expected values.
The workaround I found was to require win32/daemon and include Win32 before LOAD_PATH dance (yes it is very hackish and I admit not understanding everything I'm doing :D)
Let's continue understanding the code :)
Line 12 and 13 I'm seeing a comment insisting to have a complete path for the logfile on windows and we have a relative path just below. Not sure it will work ;-)
Well, executing the scritp, fails. Correcting the logfile variable with the complete path, my line become :
logfile = "C:\\aa\\foreman\\proxyservice.log"
Yes I know, logfile is hardcoded for the moment, testing purposes :) The good way would have been reuse settings.yml option.
Be careful, you need double backslashes or it will not work.
Now every small bugs have been fixed, it is time to see how well our proxy is starting :
C:\AA\foreman\smart\bin>net start "smart proxy" The service is not responding to the control function. More help is available by typing NET HELPMSG 2186.
No logs are created. I don't know what is happening at all :/