0

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.

4

1 回答 1

0

如果您确定密码正确,则您指定的用户可能没有作为服务运行的正确权限。尝试在 Windows 服务应用程序 (services.msc)登录选项卡上输入帐户信息,这将让您知道该用户是否存在问题。

但除此之外,我不知道如果没有安装 Ruby,你将如何实现这一点。您的服务的可执行路径设置为 .rb 文件——如果不是 Ruby,您希望 Windows 启动哪个应用程序来运行该文件?

于 2013-03-12T03:37:47.497 回答