jenkins service fail to start on windows 2008

烈酒焚心 提交于 2019-12-04 12:48:00

Version 1.498 has stronger security which can break Jenkins Slave as a service.

https://issues.jenkins-ci.org/browse/JENKINS-16273

Recommendations include:

  1. Stop service
  2. Uninstall the service if it exists dos (sc delete jenkinsslave-C__Jenkins)
  3. Delete the old jenkins-slave.exe, slave.jar and jenkins-slave.xml
  4. Start the web client and let it install the service
  5. Edit the jenkins-slave.xml so the it looks like this the important part is the jnlpCredentials <arguments>-Xrs -jar "%BASE%\slave.jar" -jnlpCredentials <user>:<password> -jnlpUrl http://<your server>/computer/<slave name>/slave-agent.jnlp</arguments>

I found deleting slave.jar and starting the web client as a logged in user worked best, you get a secret and don't need to edit the XML.

If I don't delete slave.jar that I found editing jenkins-slave.xml and removing the secret in arguments works without any credentials at all (a security hole?). See jenkins-slave.err

"-secret" is not a valid option

jenkins-slave.xml

...
<service>
  <id>jenkinsslave-D__Jenkins</id>
  <name>Jenkins Slave</name>
...
  <executable>C:\Program Files\Java\jre7\bin\java.exe</executable>
  <arguments>-Xrs  -jar "%BASE%\slave.jar" -jnlpUrl http://jenkins.domain/jenkins/computer/mycomputername/slave-agent.jnlp </arguments> <!-- -secret fafd7bf18fdcc48ffb17fe1ff0a072ce5d33b004769b351e9d633f875b63fb59 -->
...

I had similar problems on windows 2003 server. I had already installed .net framwork 4.0 but jenkins (v1.4.60) does not work with this framework. After installing .net framework 2.0 (v2.0.50727) the problem was resolved.

Suggestion: if you can at all avoid it, do not run Jenkins as a service on Windows - you may get into all kinds of problems connected to permissions and running in the background. The downside is that it won't start automatically when the machine restarts, but more often than not one can live with that. In my experience Jenkins is very robust as far as crashing is concerned. If you want to be extra careful - write a wrapper that checks every so often that Jenkins is alive (say, via trying to connect to it via HTTP) and restarts it if it has died.

Attached is a Python script that does that (no warranties, liabilities, etc.):

'''Usage:
hudson.py [<http-port>]'''

# Script to start/revive Hudson/Jenkins
# The script checks if Hudson is alive by trying to connect to its HTTP port
# if connection fails - it tries to restart Hudson 

import sys
import time
import httplib
import os

HTTPTimeout = 10
CheckInterval = 300
DefaultHudsonPort = 8081

if (__name__ == '__main__'):
    if len(sys.argv) > 2:
        print __doc__
        sys.exit(1)
    elif len(sys.argv) == 2:
        portNum = int(sys.argv[1])
    else:
        portNum = DefaultHudsonPort

    httpConnection = None
    while True:
        if not httpConnection:
            httpConnection = httplib.HTTPConnection("127.0.0.1", portNum, timeout = HTTPTimeout)
        try:
            httpConnection.connect()
            httpConnection.close()
        except:
            print "(Re)Starting Hudson/Jenkins on port %d" % portNum
            os.system("java -jar hudson.war --httpPort=%d" % portNum)
        time.sleep(CheckInterval)

I had the same problem but for me it was a problem with the jenkins.xml configuration file. It was not proper XML and thus Jenkins could not load it properly. I found out that it was a configuration error by executing jenkins.exe in a command prompt as administrator, it gave me a proper error output.

JayBofMA

I found the default setting of the Jenkins service to allow only 256m of HEAP. I guess they expected us to code only "Hello World". I found this after occasional PermGen errors. But I found that I could not correct jenkins.xml with all of,

-Xrs -Xms<value> -Xmx<value> --XX:PermSize=<value> --XX:MaxPermSize=<value>

I could only start Jenkins while setting,

-Xrs -Xms<value> -XX:MaxPermSize=<value>

I got same issue & resolved by setting up Java dir path.

Shubhankar Raj

The Answer provided by KCD is complete and quite relevant. But some of the times we face this issue due to a silly mistake too.

I also faced a similar problem, where i was getting the error message when I initiated Jenkins from COMMAND PROMPT.

The command that I was entering was,

$: start jenkins.exe

After when I referred my own notes, I found the issue to be much simpler. I was using the command wrongly. It should have been:

$: jenkins.exe start/stop/restart

On entering the commands correctly, the issue got resolved.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!