We have an existing Jenkins install that I run from the command line. I want to start using it as a Windows Service instead, so that it launches when the machine restarts, without requiring someone to log in.
I have read about how to do it, but I am worried that it might break our existing setup, the jobs and other scripts that rely on the current location. Apparently when you go to Install Jenkins as a Windows Service, it asks you for a location for JENKINS_HOME.
Can I just give it the existing location? Will it just work or is there a danger of it wiping out what's there? And if I want to be safe and back up everything just in case, can I just make a copy of the existing .jenkins folder and then copy it back if something goes wrong? Or are there other files somewhere that I need to back up?
My question is basically the same as this one, which never got an answer:
Installing existing Jenkins as a Windows Service
Thanks
You should just be able to do this directly from the UI. (It used to be documented on the Jenkins wiki, but that's presently down.)
Fire up your command line Jenkins java -jar -jenkins.war, go to "Manage Jenkins" (${JENKINS_URL}/manage). You should see an icon "Install as Windows Service".
Click on it and you arrive at ${JENKINS_URL}/install. Point it at your existing install and click "Install". You will get a prompt to restart as a service and then it restarts.
You're done. You should see in your logs the system restarting messages:
2021-09-10 00:25:44.077+0000 [id=96] INFO jenkins.model.Jenkins#cleanUp: Stopping Jenkins
2021-09-10 00:25:44.080+0000 [id=96] INFO jenkins.model.Jenkins$18#onAttained: Started termination
2021-09-10 00:25:44.099+0000 [id=96] INFO jenkins.model.Jenkins$18#onAttained: Completed termination
2021-09-10 00:25:44.100+0000 [id=96] INFO jenkins.model.Jenkins#_cleanUpDisconnectComputers: Starting node disconnection
2021-09-10 00:25:44.115+0000 [id=96] INFO jenkins.model.Jenkins#_cleanUpShutdownPluginManager: Stopping plugin manager
2021-09-10 00:25:44.115+0000 [id=96] INFO jenkins.model.Jenkins#_cleanUpPersistQueue: Persisting build queue
2021-09-10 00:25:44.127+0000 [id=96] INFO jenkins.model.Jenkins#_cleanUpAwaitDisconnects: Waiting for node disconnection completion
2021-09-10 00:25:44.127+0000 [id=96] INFO jenkins.model.Jenkins#cleanUp: Jenkins stopped
[.jenkins] $ C:\Users\ \.jenkins\jenkins.exe start
2021-09-09 17:25:45,153 INFO - Starting the service with id 'jenkins'
You should also now see the jenkins service running in Windows Services:
You can manage it via the Services UI, the command line via SC, or the jenkins.exe binary:
NOTE: The same security caveats regarding running as LocalSystem apply regardless of if using this mechanism or the MSI install. Recommend changing to run as a local user; needs LogonAsService permission (Using the LocalSystem Account as a Service Logon Account, Why running a service as Local System is bad on windows). Local Security Policy > Local Policies > User Rights Management > Log on as a service.
C:\>sc query jenkins
SERVICE_NAME: jenkins
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING
(STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
C:\> sc stop jenkins
SERVICE_NAME: jenkins
TYPE : 10 WIN32_OWN_PROCESS
STATE : 3 STOP_PENDING
(STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
C:\> sc delete jenkins
[SC] DeleteService SUCCESS
C:\>
C:\Users\ \.jenkins> jenkins.exe /?
A wrapper binary that can be used to host executables as Windows services
Usage: winsw [/redirect file] <command> [<args>]
Missing arguments trigger the service mode
Available commands:
install install the service to Windows Service Controller
uninstall uninstall the service
start start the service (must be installed before)
stop stop the service
stopwait stop the service and wait until it's actually stopped
restart restart the service
restart! self-restart (can be called from child processes)
status check the current status of the service
test check if the service can be started and then stopped
testwait starts the service and waits until a key is pressed then stops the service
version print the version info
help print the help info (aliases: -h,--help,-?,/?)
Extra options:
/redirect redirect the wrapper's STDOUT and STDERR to the specified file
WinSW 2.9.0.0
More info: https://github.com/kohsuke/winsw
Bug tracker: https://github.com/kohsuke/winsw/issues
Images captured from 2.303.1 on Win 10 Enterprise; YMMV.
Related
I'm trying to install Quartz.NET as a windows service on Windows 10.
The version of Quartz.NET is v2.6.2 and i have used this tutorial to do it. In other OS's like Windows 7 and Windows Server 2012 i have installed this version successfully.
When i run the command to instal as a service:
C:\Program Files (x86)\Quartz.NET>Quartz.Server.exe install
I have the following successful message:
Configuration Result:
[Success] Name QuartzServer
[Success] DisplayName Quartz Server
[Success] Description Quartz Job Scheduling Server
[Success] ServiceName QuartzServer
Topshelf v3.1.135.0, .NET Framework v4.0.30319.42000
Running a transacted installation.
Beginning the Install phase of the installation.
Installing Quartz Server service
Installing service QuartzServer...
Service QuartzServer has been successfully installed.
Creating EventLog source QuartzServer in log Application...
The Install phase completed successfully, and the Commit phase is beginning.
The Commit phase completed successfully.
The transacted install has completed.
But when i run the following command (Quartz.Server.exe -i) to see whether my installation has been successful installed, i have the following message:
C:\Program Files (x86)\Quartz.NET>Quartz.Server.exe -i
Topshelf.HostFactory Error: 0 : An exception occurred creating the host, Topshelf.HostConfigurationException: The service was not properly configured:
[Failure] Command Line An unknown command-line option was found: SWITCH: i (True)
[Success] Name QuartzServer
[Success] DisplayName Quartz Server
[Success] Description Quartz Job Scheduling Server
[Success] ServiceName QuartzServer
at Topshelf.Configurators.ValidateConfigurationResult.CompileResults(IEnumerable1 results)
at Topshelf.HostFactory.New(Action1 configureCallback)
Topshelf.HostFactory Error: 0 : The service terminated abnormally, Topshelf.HostConfigurationException: The service was not properly configured:
[Failure] Command Line An unknown command-line option was found: SWITCH: i (True)
[Success] Name QuartzServer
[Success] DisplayName Quartz Server
[Success] Description Quartz Job Scheduling Server
[Success] ServiceName QuartzServer
at Topshelf.Configurators.ValidateConfigurationResult.CompileResults(IEnumerable1 results)
at Topshelf.HostFactory.New(Action1 configureCallback)
at Topshelf.HostFactory.Run(Action`1 configureCallback)
All of the commands have been run in Administration mode.
Is there any configuration that i have missed on Windows 10?
EDIT
I don't have access to start and stop buttons in Quartz Server windows service, they are disabled.
If i run Quartz.Server.exe on command prompt its executes the scheduler perfectly. But when i run Quartz.Server.exe -i it gives me the error that i have mention on my first post. And i still don't have access to start and stop buttons
EDIT 2
I have installed the last version of Quartz and the problem is the same comparing to previous version, except the unknown command-line option was found (see error message).
Quartz v2.6.2
Topshelf v3.1.4.357038
Topshelf.HostFactory Error: 0 : An exception occurred creating the host, Topshelf.HostConfigurationException: The service was not properly configured:
[Failure] Command Line An unknown command-line option was found: SWITCH: i (True)
Quartz V3.0.7
Topshelf v4.1.0.172
Topshelf.HostFactory Error: 0 : An exception occurred creating the host, Topshelf.HostConfigurationException: The service was not properly configured:
[Failure] Command Line An unknown command-line option was found: DEFINE: i =
Maybe this could be some configuration that is affecting Topshelf.
EDIT 3
I have been confirmed that this error is also being fired in Windows Server 2012 R2 Standard production server, when running the command Quartz.Server.exe -i. The difference is that in production environment we have start/stop buttons enabled, but in windows 10 machine i don't have start/stop buttons enabled.
I have Jenkins running on Windows as a service. Normally, it starts when machine starts.
After a Windows recommended update this afternoon, and a machine restart, my Jenkins just stopped working.
I start the service but it stops and shows the following warning:
"The Jenkins service on Local Computer started and then stopped. Some
services stop automatically if they are not in use by other services or
programs."
There is no "jenkins.err.log" file and if I start Jenkins with "java jenkins.war" It works fine.
Any tip whats going on? How to fix this? Please help.
Thank you very much.
I had the same problem. It appeared that the java runtime enviromment had been updated. In the jenkins installation folder there is as jenkins.wrapper.log. This contains logging from the jenkins.exe service wrapper. In my case it tried to start java from c:\Program Files\Java\jre1.8.0_144\bin.
This folder did not exist, instead, java was installed in c:\Program Files\Java\jre1.8.0_161\bin.
In the jenkins installation folder there is also a jenkins.xml. This contains the reference to the java installation in the tag. Change it to your current java installation and it will start again.
I also had this problem after each java update. But there is a version-independent absolute path, that can be used to start the java run-time: C:\ProgramData\Oracle\Java\javapath\java.exe.
I changed jenkins-slave.xml to use this path:
<executable>C:\ProgramData\Oracle\Java\javapath\java.exe</executable>
if your java path is correct, disable RunawayProcessKiller in jenkins.xml
extension enabled="**false**" className="winsw.Plugins.RunawayProcessKiller.RunawayProcessKillerExtension"
If the java.exe path is setup correctly in the jenkins.xml/jenkins-slave.xml file and the problem persists, then try to delete the jenkins_agent.pid file and restart the service.
In my case this happened after I installed some updates on my machine. After some research (jenkins.err.log) it turned out that some other application grabbed the port 8080 that was used by Jenkins up to this point.
I managed to identify the app (with TcpView) and disabled it.
Problem solved.
In my case, I installed JDK 17.0.2, but Jenkins requires version JDK 8 to 11.
Check error log under C:\Program Files\Jenkins\jenkins.err for exect error.
My issue was installation of an (unwanted) service that also listens on port 8080. That service failed to start on installation because Jenkins was running at the time, but after a reboot the rogue service started more quickly and nabbed the port. The fix was to disable the unwanted service.
from jenkins.err.log:
java.net.BindException: Address already in use: bind
Caused: java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:8080
Your first stop should be the Windows Event Viewer logs to get a better idea of the underlying error. In my case the error read:
Service cannot be started. System.ComponentModel.Win32Exception (0x80004005): Access is denied
at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 access, Boolean throwIfExited)
at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfExited)
at System.Diagnostics.Process.OpenProcessHandle(Int32 access)
at System.Diagnostics.Process.get_Handle()
at winsw.Plugins.RunawayProcessKiller.RunawayProcessKillerExtension.OnWrapperStarted()
at winsw.Extensions.WinSWExtensionManager.FireOnWrapperStarted()
at winsw.WrapperService.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
You can examine your Jenkins configuration by looking at jenkins.xml. In my case this included configuration for a RunawayProcessExtension which terminates previous instances of Jenkins before starting the new instance. The <pidfile> entry stores the location of a text file with the PID of the last known instance of Jenkins.
In my case, this <pidfile> was pointing to a PID that was no longer used by a running Jenkins process. Instead, that slot had been taken over by a system process (csrss.exe), causing the RunawayProcessExtension to throw an exception with an "access denied" message when trying to terminate it. Jenkins itself was not starting because it was expecting the RunawayProcessExtension to terminate first.
The solution was to delete the <pidfile> and then restart the service.
It is happing as Jenkins is not able to find java(jdk) path. check jdk path in jenkins.xml file
Resolved this issues
java -version
where java
check jdk/bin -- copy this jdk path
Goto jenkin.xml file and change java path
To resolve this problem follow bellow steps -
Open window task manager(use CTRL + ALT + Delete button)
Navigate to service on the task manager
Click 'Services..' button on task manager
Services window gets opened > Search the Jenkins service and re-start/Start the Jenkins service
Refer Image - Jenkins Service
Now try accessing the Jenkins, problem re-solved
Jenkins service might be stoped.Find the jenkins service in window services and click start.I tried it many times.It worked
After I build my application on Jenkins,
the output message says my build is success, however I get this error message in the end, and my website can't work...
D:\Jenkins\jobs\1.job\workspace>SC \\123.45.12.133 START w3svc
[SC] StartService FAILED 1056:
An instance of the service is already running.
Any suggestion?
It says the w3svc(World Wide Web publishing service) can not start by Jenkins.
So you should start it manually by following steps:
Open your services in administrative tool
Right click w3svc(World Wide Web publishing service) and re-start it.
Or use command line and input sc start w3svc
When trying to restart an existing windows service via NSSM, I randomly get the below message which is written to the error log/error output. Any ideas on how to rectify? Ideally, accept as a valid response.
Unexpected status SERVICE_START_PENDING in response to START control
You will get "SERVICE_START_PENDING" if the the service takes too long to start (it means the service hasn't told Windows that it's started yet). "Too long" is up to the application issuing the start request. In the case of NSSM this appears to be very short, so if your system is under load the service is taking longer to start than NSSM expects.
There appears to be no way to tell NSSM how long a start or stop operation should take. For stop requests it even ignores its own shutdown timeout settings. Your option then for using NSSM is to compile from source and add a timeout option. Otherwise use a different tool, e.g. net:
net stop <service>
net start <service>
I believe that this issue was caused by the service itself.
It is highly probable that the service has bug and hang, fail, or take too much time to stop properly. Which raise issue when try to start it.
If the service fail:
In my opinion, there is a potential workaround,by setting up a service recovery option in the service properties. Then select "Run a program" when the service failed.
Then code a batch to get the PID of this service and kill it, then use NSSM to start it again.
In this batch you may use "SC query" command to check the service status:
C:\Windows>sc query "MyService" | find "STATE"
STATE : 3 STOP_PENDING
Note that if you use NSSM only to hide the windows, you may achieve the same goal with the Task Scheduler only.
In the "General" tab on task property. If you select "Run whether user is logged on or not", this will run from session 0 which won't show any window to you.
Then what you need to do on your scheduled task are, to kill / restart the target process itself as you do now. This will work more robustly.
If the service is not an official windows service but more an EXE program file (dev on your side) then converted to a services with NSSM, there is a high chance of failure.
It could be better to rewrite/recompile the program as an actual Windows service.
The problem is that NSSM is timing out waiting for your service to start. Unfortunately it does not seem to be possible to provide NSSM with a custom timespan for the service start-up timeout.
One workaround is still use NSSM to install the service, but then use PowerShell to start and stop the service. PowerShell allows you to specify your own wait timeout (since you probably don't want your script to wait indefinitely).
$serviceName = 'My service'
$service = Get-Service $serviceName -ErrorAction Ignore
Write-Verbose "Starting service '$serviceName'."
$service.Start()
$waitTimeout = New-TimeSpan -Seconds 5
$service.WaitForStatus([System.ServiceProcess.ServiceControllerStatus]::Running, $waitTimeout)
You can read more about the PowerShell Get-Service command here: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service
Recently happened to me... not only I cannot restart the service but also stop it is not possible neither.
Lets kill it.
Identify the process id (PID). Replace [SERVICE-NAME] with your service's name.
sc queryex "[SERVICE-NAME]"
You should get something like this:
SERVICE_NAME: xxxxxxxxx
TYPE : 30 WIN32
STATE : 4 RUNNING
(STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
PID : 4812
FLAGS :
Manually kill the process. Replace [PID] with the value from the previous step.
taskkill /pid [PID] /f
This error is also related to
Windows could not stop the [SERVICE-NAME] service on Local Computer.
Error 1053: The service did not respond to the start or control
request in a timely fashion.
What I have; I have putty.exe to access a remote ubuntu machine xxx.xx.xxx.xx.
What I want; I want that when I run my test cases on this remote machine using jenkins it would launch a browser that I can see popping up on my windows machine.
What I have tried; I have tried to use firefox with Xvfb(both located on remote machine) but that is headless and I cant see errors, I cant get much help from reports. I want to see whats happening on UI
So I wanted to use remote webdriver. I tried to register on remote machine as;used putty.exe
sudo java -jar selenium-server-standalone-2.35.0.jar -role node -hub http://localhost/xxx.xx.xxx.xx:4444/grid/register
but that gave error :
Sep 27, 2013 9:24:24 AM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a selenium grid node
Sep 27, 2013 9:24:24 AM org.openqa.grid.internal.utils.SelfRegisteringRemote startRemoteServer
WARNING: error getting the parameters from the hub. The node may end up with wrong timeouts.The target server failed to respond
09:24:24.961 INFO - Java: Oracle Corporation 23.7-b01
09:24:24.962 INFO - OS: Linux 3.5.0-21-generic amd64
09:24:24.971 INFO - v2.35.0, with Core v2.35.0. Built from revision c916b9d
09:24:25.111 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:5555/wd/hub
09:24:25.113 INFO - Version Jetty/5.1.x
09:24:25.114 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
09:24:25.115 INFO - Started HttpContext[/selenium-server,/selenium-server]
09:24:25.116 INFO - Started HttpContext[/,/]
09:24:36.415 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler#49af0a45
09:24:36.416 INFO - Started HttpContext[/wd,/wd]
09:24:36.423 INFO - Started SocketListener on 0.0.0.0:5555
09:24:36.426 INFO - Started org.openqa.jetty.jetty.Server#1f4a8824
09:24:36.428 INFO - using the json request : {"class":"org.openqa.grid.common.RegistrationRequest","capabilities":[{"platform":"LINUX","seleniumProtocol":"Selenium","browserName":"*firefox","maxInstances":5},{"platform":"LINUX","seleniumProtocol":"Selenium","browserName":"*googlechrome","maxInstances":5},{"platform":"LINUX","seleniumProtocol":"Selenium","browserName":"*iexplore","maxInstances":1},{"platform":"LINUX","seleniumProtocol":"WebDriver","browserName":"firefox","maxInstances":5},{"platform":"LINUX","seleniumProtocol":"WebDriver","browserName":"chrome","maxInstances":5},{"platform":"LINUX","seleniumProtocol":"WebDriver","browserName":"internet explorer","maxInstances":1}],"configuration":{"port":5555,"register":true,"host":"10.158.96.150","proxy":"org.openqa.grid.selenium.proxy.DefaultRemoteProxy","maxSession":5,"role":"node","hubHost":"localhost","registerCycle":5000,"hub":"http://localhost/184.73.224.98:4444/grid/register","hubPort":-1,"url":"http://10.158.96.150:5555","remoteHost":"http://10.158.96.150:5555"}}
09:24:36.430 INFO - Starting auto register thread. Will try to register every 5000 ms.
09:24:36.430 INFO - Registering the node to hub :http://localhost:-1/grid/register
09:24:36.446 INFO - couldn't register this node : Error sending the registration request.
09:24:41.479 INFO - couldn't register this node : Hub is down or not responding: Hub is down or not responding.
I have already tried :
http://rationaleemotions.wordpress.com/2012/01/23/setting-up-grid2-and-working-with-it/
https://code.google.com/p/selenium/wiki/Grid2
Understanding Selenium Grid2 implementation running on EC2
but these failed on initial step when I have to register a node on remote ubuntu machine.
Its not entirely clear what your error is. This might help where you can vnc onto a headless Xvfb box using ssh tunnels
after installing any missing packages on your remote server
Xvfb -screen 0 800x600x16 -ac &
export DISPLAY=:0
xterm &
java -jar selenium-server-standalone-2.35.0.jar -role node -hub http://mywebsiteip:4444/grid/register
then tunnel to your server from your own machine
ssh -l kaltpost -L 5900:localhost:5900 mywebsiteip 'x11vnc -localhost -display :0'
which will wait, so in another terminal
vncviewer localhost&
Which is all taken from here http://gpio.kaltpost.de/?page_id=84
++edit
I just saw you started your selenium server with the ip of the host, this needs to be localhost and then mywebsite id when you connect your tests to it