I have a JRuby program that I want to be a windows service. I have seen some things on creating a service with Ruby, but we don't want to install ruby on our client machines. It appears to be not supported in JRuby.
I created a dummy program to try this out:
path = "C:/tmp/my-svc.log"
if File.exists?(path)
File.open(path,"a"){|f| f.write(" called again\n")}
else
File.open(path,"w"){|f| f.write(" called first time\n")}
end
while true do
sleep 5
puts 'I am a service'
end
I did this:
Z:\play>sc.exe create "larz service 2.1" binpath= "C:\jruby-1.6.7.2\bin\jruby -S Z:\play\my-win-svc.rb" start= auto
[SC] CreateService SUCCESS
Trying to start it I got this error:
Z:\play>sc start "larz service 2.1"
[SC] StartService FAILED with error 193.
Z:\play>sc query "larz service 2.1"
SERVICE_NAME: larz service 2.1`
TYPE : 10 WIN32_OWN_PROCESS`
STATE : 1 STOPPED
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
I have seen alot of posts on the web on different ways to create windows services, using initsrv.exe, powershell, running CMD, editing the registry and so on, but I am not sure what is really going on or if I need to call some API. It doesn't appear as if the other approaches add any specific start parameters that I could tell. In addition, I added code at the beginning of my test service to write to a file in /tmp and the file is not being written so when I try to start the program, it never actually is being executed.
Thanks ..
Ok, so I got a little farther, but still mystified
Z:\play>sc config "larz service 2.2" obj= EEE\lgud password= "Ssssssss@"
[SC] ChangeServiceConfig SUCCESS
Z:\play>sc start "larz service 2.2"
[SC] StartService FAILED 1069:
the service did not start due to a logon failure.
It seems I entered the correct format for user/pw as at other times it errored out on the config command.