Restarting Hudson on Windows - windows

I've been having an issue with Hudson on windows.
Whenever I update Hudson or a plugin I get the option to restart when no jobs are running.
If I click this button Hudson hangs and doesn't restart. I've tried restarting the Hudson service but this doesn't help, so end up having to reboot the box to bring Hudson back online.
I've just updated to the most recent version, but didn't click the restart button and it's now vanished.
Is there a correct way to restart Hudson on windows?
Cheers
Tom

I have a this problem once in a while too. For some reason the Hudson server does not shut down completely and the server that starts up, can not use the port. To fix that problem, I run `netstat -n -o'. This way I can find out the process ID that holds the port and kill that app through taskmanager. Now I can restart the service and Hudson comes up fine.
For the last few weeks I had a similar problem. The description says, that it restarts the app, when no processes are running. I missed out on one job that was hold in the build queue and because of a faulty configuration never actually build, therefore preventing Hudson from restarting.
After all of your jobs are finished and your server does not restart. Just visit the restart page again http://server:port/restart and try to restart again. If that doesn't work stop the service and start it again.
UPDATE:
Since I grew tired of physically logging into the Hudson/Jenkins server, I now use following commands to run the kill remotely. These commands assume that you run the service with a dedicated user (e.g. JenkinsUser). If another process running with the same credentials than the service does and might start java.exe, you need to run the netstat which needs to be executed locally on the Jenkins server or by using rexec (this was not an option for me).
:: get the pid of jenkins java.exe
tasklist /S %JENKINSSERVER% /FI "IMAGENAME eq java.exe" /FI "USERNAME eq %DOMAIN\USERNAME%"
:: terminate process use pid from previous command (instead of 1234)
taskkill /S %JENKINSSERVER% /F /T /PID 1234
:: stop the Jenkins service (just in case the service is hanging)
sc \\%JENKINSSERVER% stop Jenkins
:: start the Jenkins service again
sc \\%JENKINSSERVER% start Jenkins
If I have to much time, I might create a script out of it.

If the Slave node has the slave.jar used as a windows service, that service is defined as "Automatic".
It means it will try to contact the master periodically if the connection has been severed.
You shouldn't click on anything on the server side (in the Node definition) to restart said Node: it should be back online automatically.

If you've installed Jenkins on a TomCat server, one alternative solution is to simply restart your Apache TomCat service.

Related

Terminating port of spring boot application in Eclipse

Terminated by clicking on Red Icon in console tab but when I rerun it is saying port is already in use.
I terminated port using Taskkill command in command prompt. Any suggestions on terminating it from Eclipse would be helpful instead of command prompt
Usually terminating application from Eclipse helps. Sometimes, though, it doesn't help. In such cases, I have to restart the eclipse. Unfortunately, I don't have any better solution. There might be something wrong with your application, if this issue happens too often for you. Eclipse usually tries to "gracefully" shut down the application and release resources, before shutting down the server. Maybe during this time the application "hangs" and doesn't respond. There could be many reasons for that. One of them: your application doesn't close file resources correctly, with try... finally, and so on.
To summarise: In 95% of the cases, shutting down the server from eclipse works. If it doesn't, then you have to restart the eclipse, or maybe even kill the process from the command-line. If it happens too often, let's say in 50% of the cases, then there is something wrong with your application.
Open Eclipse
Go to Servers panel
Right click on Tomcat Server select Open, Overview window will appear.
Open the Portstab. You will get the following:
Tomcat adminport
HTTP/1.1
AJP/1.3
I changed the port number of HTTP/1.1 (i.e. to 8081)
You might have to also change the port of Tomcat adminport (i.e. to 8006) and of AJP/1.3 (i.e. to 8010).
Access your app in the browser at http://localhost:8081/...
I found the best way to stop spring from holding the port was to write a script that looks for the process holding the port and auto kill it. Then attach that script to an external tool job in eclipse. I adapted a powershell script I found. Called it kill-port.ps1 and is located in base of the report where I had the issue.
param ($port)
$foundProcesses = netstat -ano | findstr :$port
$activePortPattern = ":$port\s.+LISTENING\s+\d+$"
$pidNumberPattern = "\d+$"
IF ($foundProcesses | Select-String -Pattern $activePortPattern -Quiet) {
$matches = $foundProcesses | Select-String -Pattern $activePortPattern
$firstMatch = $matches.Matches.Get(0).Value
$pidNumber = [regex]::match($firstMatch, $pidNumberPattern).Value
taskkill /pid $pidNumber /f
}
Then set up an external tool configuration
Location: C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe
Argument: ${workspace_loc:/workspacename/kill-port.ps1} 8080
Now I just run the kill command after each test where I know it leaves the port bond to a process. Not the most elegant but easier then running a few commands in a shell. This is windows specific but I am sure the same type script can be created for Unix.

Is it possible to force to kill windows service using Octopus?

My octopus installs Windows Service in a machine, but sometimes it can't stop the service so it doesn't deploy.
If I manually go to the machine and try to stop the service, I can't. But if I first go to Task Manager and kill the process of the service, then I can stop the service.
Does Octopus already have a built-in feature to do this for me? Or should I create a .bat to execute it before reinstalling windows service?
Same to Ryan's process, we use the command in this format to kill process that would not gracefully shutdown
taskkill /im Processname /f
Just a note, this takes Process Name not Service Name, and all services share the same process name will be killed.
You could try using a custom powershell pre-deployment script (enable the custom deployment scripts feature for your deployment step) or by placing this in a predeploy.ps1 file in your nuget package.
kill -processname serviceName
If you import the step template Stop Service With Kill you can add this as a deployment step.
The documentation here provides a step by step way to do this

How to force Jenkins to launch webpage/ cmd prompt in client (user's) machine?

The job that I was trying to create in Jenkins would require launching a webpage on the user’s browser once the build is successful (Jenkins is installed on a remote server). For doing this I put the following line in the " Build - Execute Windows batch command" section of the job’s Configure page:
START http://google.com
While the build was successful, it did not launch the page. I have a hunch, this line will try to launch the webpage in the remote Jenkins server (it did not launch anything in the slave node though). My question is, how do I force the Jenkins job to launch the webpage in the user’s default browser?
I tried launching client's cmd.exe - this did not work either.
Jenkins master, slave, user's client - everything is on Windows. Jenkins version 1.46.
Thanks!
By "launch in client's machine" you mean the user that is accessing the web interface of Jenkins? No, this won't happen. It can be quite a security risk too.
You can do what you are asking either on the master or the slave. Jenkins does not directly execute anything that is not on master/slave. It is possible to spawn a slave on user's machine, and when the job is run, it will execute the command on the slave.
Or if the user provides his/her computer IP address as a parameter to the job, you could use PsExec to connect to user's computer to execute a command.

Add nginx.exe as Windows system service (like Apache)?

I set up NGINX as a front end server for static content and I use Apache as a back-end server for other thing.
The thing is I can't find a logical answer that allows me to make nginx.exe a Windows system service (like my Apache).
Any come across an answer to this?
How to do it with Windows Service Wrapper
(Note: There are easier alternatives by now - see also solutions described here below using chocolatey package manager by suneg and using NSSM directly from Adamy)
Download the latest version of Windows Service Wrapper via github or nuget.
Current version as of this writing is v2.2.0
Since v2.x executables for .NET2.0 and .NET4.0 are available - others only on demand.
Rename winsw-*.exe to something like nginxservice.exe.
This is the name that will show up for the process that owns your nginx process.
Place an XML file next to the exe with the same base name, e.g. nginxservice.xml. The contents should be like below (verify your nginx location).
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<executable>c:\nginx\nginx.exe</executable>
<logpath>c:\nginx\</logpath>
<logmode>roll</logmode>
<depend></depend>
<startargument>-p</startargument>
<startargument>c:\nginx</startargument>
<stopexecutable>c:\nginx\nginx.exe</stopexecutable>
<stopargument>-p</stopargument>
<stopargument>c:\nginx</stopargument>
<stopargument>-s</stopargument>
<stopargument>stop</stopargument>
</service>
You can find up to date details about the configuration on the config github page, a generic example showing all possible options here and an installation guide.
Run the command nginxservice.exe install as administrator.
You will now have an nginx service in your Services! (It is set to start automatically on boot; if you want to start your server, you must manually start the service (net start nginx).)
Detailed description of correctly setting up nginx as a Windows Service:
http://web.archive.org/web/20150819035021/http://misterdai.yougeezer.co.uk/posts/2009/10/16/nginx-windows-service/
Additional info not contained in above blog post:
You can find the latest version of the Windows Service Wrapper also via this Maven Repository:
http://repo.jenkins-ci.org
Examples for Maven + Gradle:
<dependency>
<groupId>com.sun.winsw</groupId>
<artifactId>winsw</artifactId>
<version>2.2.0</version>
<classifier>bin</classifier>
<packaging>exe</packaging>
</dependency>
<repository>
<id>jenkinsci</id>
<name>jenkinsci-releases</name>
<url>http://repo.jenkins-ci.org/releases</url>
</repository>
compile "com.sun.winsw:winsw:2.2.0"
repositories {
mavenCentral()
maven { url http://repo.jenkins-ci.org/releases }
}
Download NSSM form
http://nssm.cc/download .
"Run %NSSM_HOME%\nssm.exe install “Nginx”"
Select the Nginx executable in the NSSM dialog, then OK.
Go to Services and start the new created service "Nginx", done.
You can using start.bat and stop.bat to realize the same effect.
start.bat
#ECHO OFF
REM Start Nginx
tasklist /FI "IMAGENAME eq nginx.exe" 2>NUL | find /I /N "nginx.exe">NUL
IF NOT "%ERRORLEVEL%"=="0" (
REM Nginx is NOT running, so start it
c:
cd \nginx
start nginx.exe
ECHO Nginx started.
) else (
ECHO Nginx is already running.
)
stop.bat
#ECHO OFF
REM Stop Nginx
tasklist /FI "IMAGENAME eq nginx.exe" 2>NUL | find /I /N "nginx.exe">NUL
IF "%ERRORLEVEL%"=="0" (
REM Nginx is currently running, so quit it
c:
cd \nginx
nginx.exe -s quit
ECHO Nginx quit issued.
) else (
ECHO Nginx is not currently running.
)
SC.EXE will only work for executables that already support the Windows Services API and can respond properly to start and stop requests from the Services Control Manager (SCM). Other regular applications, not specifically written as a service, will simply fail to start (usually with error 1053)...
For those exe's, you need a "service wrapper" -- a small utility that can accept the start/stop commands from the SCM and run/terminate your application accordingly. Microsoft provides Srvany (which is free yet very basic), but there are several other free and commercial alternatives.
BTW, you should check out this guide showing how to run Nginix as a service, especially step 7 which discusses how to stop Nginix properly. Not every wrapper will support that functionality (Srvany doesn't)...
The easiest way I've found, was using the Chocolatey package manager.
Once Chocolatey is installed, you open an administrative prompt and type:
choco install nginx
You now have a Windows service named 'nginx' running.
NSSM is the best tool to run Nginx as a service.
If you do not want to use any external 3rd party software then you can implement any of these two methods.
Windows Task Scheduler
Windows startup shortcut
Windows Task Scheduler
As mentioned in this answer prepare one start.bat file.
Put this file where nginx.exe is present.
Open windows task scheduler and set up the task as described in this answer to run it indefinitely.
Do not forget to run this task as the highest privilege with the system account, more details can be found here.
Make the task to start daily at a certain time, through the bat file it will check whether the service is already running to avoid creating multiple nginx.exe instances.
If due to some reason Nginx shuts down, within 5 minutes it will start.
Windows Startup shortcut
Create one shortcut of nginx.exe and put it in the startup folder of Windows.
Follow this answer to find your startup location.
Nginx will run automatically whenever you log in to the system.
This one is the easiest. However, it is dependent on user profile i.e. if you are running Nginx on a server, it will run only for your user account, when you log off it stops.
This is ideal for dev environment.
Download zip file from here.
Extract nginx-service.exe from winginx\build and run it.
Rather than turning nginx into a service, or using CMD to start a process, which really doesn't seem to work. I found that Powershell makes it easy to startup nginx as a detached process. I've combined starting nginx with PHP. Below is the script, named "start-nginx.ps1"
$fcgiPort = "127.0.0.1:9000"
$PHPini = "c:\php\php.ini"
$ErrorActionPreference = "SilentlyContinue"
function restart {
Push-Location /nginx
Stop-Process -Force -Name nginx
Start-Process ./nginx.exe -WindowStyle Hidden
Stop-Process -Force -Name php-cgi
Start-Process "c:\php\php-cgi.exe" -ArgumentList ("-b" + $fcgiPort + " -c " + $PHPini) -WindowStyle Hidden
Pop-Location
}
restart
This script can be executed from any directory, but needs to be customized for where your nginx installation is located.
This script includes a silent attempt to kill nginx and PHP before launching both.
Windows systems are supposed to recognize ".ps1" files as powershell, even in the CMD prompt.
I created another small script to kill the running processes, which simply removes the "start-process" lines from this file.
To run at startup, I used the win-R command to navigate to the directory shell:startup
Placing a shortcut to the startup script in this directory, nginx starts at boot!
Powershell also includes a much more sophisticated ability to schedule tasks, and it is possible to schedule this script to run at startup. See This Link
From the article:
>powershell
$trigger = New-JobTrigger -AtStartup -RandomDelay 00:00:30
Register-ScheduledJob -Trigger $trigger -FilePath $HOME/start-nginx.ps1 -Name startNginx
Combined, I think this approach gets you everything you'd need from an nginx windows service and doesn't require any third-party applications.
Official nginx wiki referes on winginx for this purpose. It builds exe-installer in linux environment.
Process looks like this:
sudo apt-get install nsis make
wget https://github.com/InvGate/winginx/archive/master.zip
unzip master.zip
cd winginx-master/
make
ls -lh ./build/nginx-service.exe
To get actual versions you should specify them in Makefile.

How to kill a glassfish server in Windows?

I tried to start a glassfishv3 server in my windows XP system with the command "asadmin start-domain". The start failed due to a timeout. When I try to start again I get an error saying that the port 4848 is allready in use by another process. When I try to stop the server with "asadmin stop-domain" I get the error that it is not running.
Any idea how to solve this deadlock? I cannot find a Windows process with the name glassfish or asadmin to kill.
The process will be java.exe
You can use one of the sysinternals tools, like tcpview.exe for example to see which program is actually using that port.
Adding to Alexis' answer,
jps -v
will show you more about the java processes. Note the pid. You must have configured your path correctly for this to work.
Then do
taskkill /pid <pid>
You can also use jps to list all the Java processes on you machine. The GlassFish server main class is called ASMain

Resources