Jenkins Windows Service Not Starting - jenkins

Jenkins was up and running for months without issue, as a windows service.
I did some Jenkins updates (copied a newer/later .war file to the .jenkins folder) and some windows updates also occurred. The version that I have is Jenkins 2.263.3.
I did a lot of trolling through the documentation and other StackOverflow tickets and found out that the JENKINS_HOME environmental variable was missing. I added this.
Here is what my investigation reveals.
The Java environment variable is set - see below:
C:\>java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
JENKINS_HOME environmental variable is set - see below:
C:\>echo %JENKINS_HOME%
C:\Users\XXXXX\.jenkins
The Installation was under user XXXXX and the service account Log On was configured accordingly
I do not have another application using port 8080 - I checked this with sys internals.
My jenkins.xml looks like this:
<service>
<id>jenkins</id>
<name>Jenkins</name>
<description>This service runs Jenkins automation server.</description>
<env name="JENKINS_HOME" value="%BASE%"/>
<!--
if you'd like to run Jenkins with a specific version of Java, specify a full path to java.exe.
The following value assumes that you have java in your PATH.
-->
<executable>java</executable>
<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>
<!--
interactive flag causes the empty black Java window to be displayed.
I'm still debugging this.
<interactive />
-->
<logmode>rotate</logmode>
<onfailure action="restart" />
<!--
In the case WinSW gets terminated and leaks the process, we want to abort
these runaway JAR processes on startup to prevent corruption of JENKINS_HOME.
So this extension is enabled by default.
-->
<extensions>
<!-- This is a sample configuration for the RunawayProcessKiller extension. -->
<extension enabled="true"
className="winsw.Plugins.RunawayProcessKiller.RunawayProcessKillerExtension"
id="killOnStartup">
<pidfile>%BASE%\jenkins.pid</pidfile>
<stopTimeout>10000</stopTimeout>
<stopParentFirst>false</stopParentFirst>
</extension>
</extensions>
<!-- See the referenced examples for more options -->
</service>
I can start Jenkins from the command line as follows:
java -Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "C:\Users\XXXXX\.jenkins\jenkins.war" --httpPort=8080 --webroot="C:\Users\XXXXX\.jenkins\war
If I try start it from the Serice Manager I get this error - System.BadImageFormatException
One last thing, once I start Jenkins from the command line, and login to the the application, I note the following Jenkins System log:
Feb 17, 2021 10:29:31 AM INFO hudson.WebAppMain$3 run
Jenkins is fully up and running
Feb 17, 2021 10:29:57 AM WARNING hudson.lifecycle.WindowsServiceLifecycle getBaseDir
Could not find environment variable 'BASE' for Jenkins base directory. Falling back to JENKINS_HOME
Any suggestions how to get the service to start via the Service Manager?

The service is starting and stopping without issue.
The problem I suspect was that the original install of Jenkins was very old, and I presume that it may have been a 32-bit application at the time. The current updates seem to 64-bit apps. Since the original install, Jenkins was updated - with changes spanning several major releases from the original install (.war file updates). The jenkins.exe file - that starts the service was never updated.
The error message 'System.BadImageFormatException' after much research indicated that the issue was related to compatibility difference between 32/64 bit executable. I presume it was expecting a 64-bit executable but was getting a 32-bit exe.
To solve this problem I installed the latest version of Jenkins on my local PC.
On the Server I backed up the files:
jenkins.exe
jenkins.exe.config
I then stopped Jenkins on the Server, where the Service was not Starting (from the terminal window with Ctrl+D).
I then replaced these 2 files on the server with the latest files from my local installation.
Service started the first time.

Related

Multiple Jenkins on same tomcat server in linux

I want to set up 2 jenkins on same tomcat server -8.5.34 in linux.
I Downloaded https://get.jenkins.io/war-stable/latest/jenkins.war and placed in webapps folders of tomcat as jen-dev and jen-qa
However, for both Jenkins, I want to use different Jenkins home locations:
JENKINS1_HOME : /opt/jen-dev JENKINS2_HOME : /opt/jen-qa
If I try setting below variable in shell and start tomcat using bin/startup.sh, jen-dev is working fine as http://jenkins.dev.com/jen-dev.
export JENKINS_HOME="/opt/jen-dev"
How can I customize this installation to include second Jenkins home and run on same server as http://jenkins.dev.com/jen-qa?
There are three ways to set the JENKINS_HOME parameter (cf. Jenkins Wiki):
as a system environment variable,
as a system property,
as a JNDI environment entry.
The first two options will apply to the entire Tomcat server, so you need to use JNDI. Create a descriptor file $CATALINA_BASE/conf/Catalina/localhost/jen-dev.xml with content:
<Context>
<Environment type="java.lang.String" override="false"
name="JENKINS_HOME" value="/opt/jen-dev" />
</Context>
and define a similar descriptor for the other Jenkins instance.

Ubuntu tomcat9 Jenkins setup issue

I have been trying to install Jenkins on tomcat9 but when I go for the first time on http://myip:8080/jenkins to finish the setup; I have the the following error:
java.io.IOException: Read-only file system
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createTempFile(File.java:2026)
at hudson.util.AtomicFileWriter.<init>(AtomicFileWriter.java:142)
Caused: java.io.IOException: Failed to create a temporary file in /var/lib/jenkins
at hudson.util.AtomicFileWriter.<init>(AtomicFileWriter.java:144)
at hudson.util.AtomicFileWriter.<init>(AtomicFileWriter.java:109)
at hudson.util.AtomicFileWriter.<init>(AtomicFileWriter.java:84)
at hudson.util.AtomicFileWriter.<init>(AtomicFileWriter.java:74)
at hudson.util.TextFile.write(TextFile.java:116)
at jenkins.model.Jenkins.<init>(Jenkins.java:910)
at hudson.model.Hudson.<init>(Hudson.java:85)
at hudson.model.Hudson.<init>(Hudson.java:81)
at hudson.WebAppMain$3.run(WebAppMain.java:262)
Caused: hudson.util.HudsonFailedToLoad
at hudson.WebAppMain$3.run(WebAppMain.java:279)
First: Tomcat9 is working well, I can access it locally or remortly
I have created /var/lib/jenkins which is owned by jenkins (unix user I have created), I have even setup the permission to 777.
Second: if i run the war in command line 'java -jar jankins.war" ( I have exported JENKINS_HOME=/var/lib/jenkins before), then jenkins works correctly. So the war is not corrupt.
third: on tomcat, I have modified the context.xml to set up JENKINS_HOME to /var/lib/jenkins, it is working as you can see the above error (5th line).
Then in context.xml I have tried to setup JENKINS_USER to several different users (jenkins, tomcat, root etc) , I tried different ownership for /var/lib/jenkins (and group as well).
here is my context.xml:
<Context>
<Environment name="JENKINS_HOME" value="/var/lib/jenkins" type="java.lang.String" />
<Environment name="JENKINS_USER" value="jenkins" type="java.lang.String" />
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
</Context>
But nothing is working, it looks like JENKINS_USER is not taken into account and/or whatever I do the directory is read-only ....
NB: as I have read there might be some issues with JDK version, so I have tried with open-jdk-11 (at the beginning) then with open-jdk-8
Has anyone face this issue ?
If you run tomcat9 from the Ubuntu repositories, it will run as the unix user tomcat. Providing access to a user jenkins won't give permissions to tomcat. And just defining arbitrary environment variables (JENKINS_HOME, JENKINS_USER) won't make a web application magically change its identity.
All web applications in tomcat run as the same user, and that's the one that you need to provide access to.
Also, notice that Debian's Tomcat runs in a sandboxed environment (see this answer to a relevant question), so you'll need to work on the sandbox environment in addition to the owner of the files/process.

Jenkins startup process: how delete or fix warning messages

When I execute:
java -jar jenkins.war --httpPort=9090
For 2.25 version, the app starts up and works fine but I did realize in the terminal/console always appears these two warnings:
Main deleteWinstoneTempContents
WARNING: Failed to delete the temporary Winstone file /var/folders/nf/ql69b5zd7w54jw6nb5zmvck80000gn/T/winstone/jenkins.war
and
org.eclipse.jetty.util.log.JavaUtilLog warn
WARNING: Empty contextPath
How I can fix them? Even when they are warnings, I want remove them.
For the first, yes, I've confirmed the path only exists until /var/folders/nf/ql69b5zd7w54jw6nb5zmvck80000gn/T/, the rest winstone/jenkins.war does not exist.
Why does the second appear?
I have faced the same issue.But i fixed it.Please download apache-tomcat-8.5.16 or the latest one.Run the startup.bat file and type http://localhost:8080/ and you will see Apache Tomcat up & running on your local host.
Now run java -jar jenkins.war and type http://localhost:8080/jenkins/ and jenkins will be up and running on your local host.
Hope it will solve your issue.
Corrected Command:
java -jar jenkins.war -httpPort-9090

System properties management

Is there any "adequate" way to change system properties in Jenkins? What is the easiest/fastest way change them? For instance, I need to turn off the useless (in my case) pinging thread.
If you really want a quick and simple way to change a system property, you can use the script console
System.setProperty("hudson.remoting.Launcher.pingIntervalSec", 0)
But that won't survive a restart. To make it permanent, add the setting to the java args. For me (CentOS, Jenkins 2.7.1) that's a line about halfway down /etc/sysconfig/jenkins (for other distributions I believe it's /etc/default/jenkins) where you should add your option to the existing list like this:
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Dhudson.remoting.Launcher.pingIntervalSec=0"
You'll have to restart Jenkins after you make that change (thanks Mark Tickner)
If you run Jenkins on windows as a service without tomcat, you can edit jenkins.xml. Add the property in <service><arguments> before the -jar.
Than restart the service.
<service>
<!-- ... -->
<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -Dhudson.tasks.MailSender.SEND_TO_UNKNOWN_USERS=true -Dhudson.tasks.MailSender.SEND_TO_USERS_WITHOUT_READ=true -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>
The system properties available and how to set them are listed on the wiki:
https://wiki.jenkins-ci.org/display/JENKINS/Features+controlled+by+system+properties
To disable slave pinging, you can set hudson.remoting.Launcher.pingIntervalSec to 0.
System properties can be set in the same way as with any other Java program, e.g.:
java -Dhudson.remoting.Launcher.pingIntervalSec=0 -jar jenkins.war
If you use Tomcat on Windows you can edit the File C:\apache-tomcat-7.0.67\conf\catalina.properties and simply add the Line
hudson.DNSMultiCast.disabled=true
at the End of the File. Then safe the File and restart Tomcat.
I have the similar problem: I need to disable DNSMultiCast (set hudson.DNSMultiCast.disabled = false) and I can't understand how to do it
for example, https://wiki.jenkins-ci.org/display/JENKINS/Features+controlled+by+system+properties - there is such advice "...pass all of these arguments before the -jar argument..." but I run jenkins under tomcat so I am not sure I can change startup parameters.
I tried to change /etc/tomcat6/Catalina/localhost/jenkins.xml to
<?xml version="1.0" encoding="UTF-8"?>
<Context >
<Environment name="JENKINS_HOME" value="/var/jenkins"
type="java.lang.String" override="false"/>
<Environment name="hudson.DNSMultiCast.disabled" value="true"
type="java.lang.Boolean" override="false"/>
</Context>
but I didn't help.
Can someone explain how to change jenkins system properties when tomcat is used.
Maybe it's a bad hack but I set it in the pipeline job that needs the setting.
Like this:
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "") // allow formatted HTML pages to be published
It seems to work - as far as I can tell...
I followed each steps mentioned above but it fails.
So I did change the system time zone using timedatectl set-timezone Europe/London command and then I have restarted jenkins service service jenkins restart it worked.
I was using Rehdat 7.5
Jenkins version 2.168.
Jenkins Installed via yum install jenkins
I hope this will help some one.

JBoss as a windows service. Where can i set the JAVA_OPTS?

I'm running JBoss as a windows service, but i can't seem to find where i can configure the JAVA_OPTS to make it work properly.
I need to set the Xms and the Xmx.
I have tried to just run JBoss manually (run.bat) and in the same file i set the JAVA_OPTS= -Xms128m -Xmx512m. And that works.
Here is my install.bat where i install the JBoss as a service:
set JBOSS_CLASS_PATH=%JAVA_HOME%\lib\tools.jar;%JBOSS_HOME%\bin\run.jar
rem copy /Y JavaService.exe D:\PROJECT\bin\JBossService.exe
JBossService.exe -install JBoss %JAVA_HOME%\jre\bin\server\jvm.dll -Djava.class.path=%JBOSS_CLASS_PATH% -start org.jboss.Main -stop org.jboss.Shutdown -method systemExit -out %PROJECT_HOME%\log\JBoss_out.log -err %PROJECT_HOME%\log\JBoss_err.log -current D:\PROJECT\bin
net start JBoss
When i look at the info about JBoss Application Server (http://localhost:8080/web-console/) i see this info:
JVM Environment
Free Memory: 9 MB
Max Memory: 63 MB
Total Memory: 63 MB
And i MUST have more Max Memory.
Does anybody know where i can set the JAVA_OPTS when running JBoss as a service?
We use jbosssvc.exe to run JBoss as a service. It basically runs your run.bat, so you can include all the customizations you want.
http://community.jboss.org/wiki/JBossNativeWindows
In the bin directory of jboss, there's a service.bat that can install the service.
#karoberts answer is correct, although is different between version 4 and 5:
In JBoss 4:
{jboss.home}\bin\run.bat
In JBoss 5:
{jboss.home}\bin\run.conf.bat
Which one are you using?
The
service.bat
script of jboss native calls run.bat so you should put your JAVA_OPTS in there using the syntax
set "JAVA_OPTS=%JAVA_OPTS% -Dyoutoptionsgoeshere
Note: you won't find the service.bat in the bin anymore since JBoss 5. It's in a different package.
Another tip:
If you have multiple Java Versions installed on your server and JBoss(4.2.3) service needs an older Version, you have to define the JAVA var in service.bat. If you use the run.bat also sometimes, then you need to define the JAVA var there too.
I know that the service.bat calls the run.bat, but I tried just defining the JAVA var in the run.bat, when I then ran the service it ignored the new JAVA var content from run.bat
Here an example of how to set the JAVA var :
set JAVA_HOME=C:\Program Files (x86)\Java\jre6
set JAVA=%JAVA_HOME%\bin\java
If you use JavaService.exe as desribed above you can configure JVM options in the Windows Registry:
1.) Execute regedit.exe
2.) Goto HKEY_LOCAL_MACHINE\CurrentControlSet\Services\JBoss\Parameters
3.) After initial installation you find a parameter "JVM Option Count" wich is set to 1 and "JVM Option Number 0" which basically contains a class path.
4.) Increase the value of "JVM Option Count" to 3
5.) Add a REG_SZ Parameter "JVM Option Number 1" and assign it the Value -Xms128m
6.) Add a REG_SZ Parameter "JVM Option Number 2" and assign it the Value -Xmx512m
Regards

Resources