Java Service Wrapper & shutdown command - shutdown

I use JSW to wrap HSQLdb server. HSQL docs say I must connect to server and execute "shutdown" command to terminate server correctly. Is there any way to execute such shutdown command from within wrapper when I use standard service management commands like "net service stop" or button "stop" in service properties?

not quite sure what you are trying to accomplish, but assume that you are running the HSQL server as service and you want to connect from your application to it and when your application stops, it should also stop the HSQL server?
If that's so, then please take a look at the following page:
http://www.informit.com/guides/content.aspx?g=java&seqNum=619
cheers,
edit:
registering the code to cleanly shutdown HSQL as shutdown hook should work for you I think. Furthermore you can also do this with the WrapperListener.stop function (following Integration Method #3)
cheers,

Related

In Rails, how do I run certain tasks on shutdown?

I maintain a connection to a RabbitMQ server. When I safely turn the Rails Server off (via CTRL+C or whatever), how do I trigger a close to that connection?
I need an 'On shutdown' trigger. Is there one?
If you are using puma as your webserver you can add on_worker_shutdown as a callback and then execute a shell script or whatever else is needed to close the connection to RabbitMQ.

How to quit a Ruby on Raily server?

Inside a test environment I am using the wash_out GEM within a Ruby on Rails server to run a SOAP service that serves as a Proxy between two different transfer protocols.
At the end of the test run, I would like to quit the Rails server with a dedicated SOAP request.
So I implemented such a request and called inside the request exit(0). But it seems to me that exit and abort functions are hooked away because of security or other reasons.
One might argue that terminating the service within a request is a little bit harsh, but at that point I do not care how the service gets terminated. Since it does not hold any state.
I would like to avoid to patch the Rails sources so that it is later easier to update the GEMSs.
Edit:
The server is running (unfortunately) on Windows.
You could execute shell script and kill running rails process. For example if you running service on unicorn you could do something like
def exit_app
%x(kill -9 $(cat tmp/pids/unicorn.pid))
end

Unexpected status SERVICE_START_PENDING in response to START control

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.

neo4j community edition 2.1.6 server process running even after server stop command executed

I know at least a few of us had this issue come up...I am issuing the command to start the server and yet it tells me that a server process is still running at 17922...I then try the following:
./bin/neo4j status
And it tells me: "Neo4j Server is not running"
Then I issue the command to start a new server: ./bin/neo4j start
and I get the following:
Another server-process is running with [17922], cannot start a new one. Exiting.
Not looking to run multiple Neo4J servers, so I'd like to stop whatever is running in the background.
Seems the process is not nicely responding for whatever reason. You might want to inspect the log files (data/log/* and data/graph.db/messages.log) to get more insight.
To terminate the process use kill 17922. If that does not help, kill -9 17922.

Executing script on a UNIX server from PowerShell

I have a PowerShell script hosted in Windows Server 2008 R2. This script need to invoke a UNIX script residing in a UNIX server. After completion of execution of script it must return the output to the calling script. (PowerShell Script). I am implementing it in highly secured servers. Hence cannot use third party built tools/Libraries unless they are authenticated and approved by standards. If there is any standard library which I can make use of and accomplish this task will be appreciated.
There is no "native" way to do it that I'm aware of.
The most secure method I can think of offhand which will be accepted by your review board is to use ssh with keys for authentication. Yes, you'll have to acquire & install an SSH client for Windows, but if your servers are "highly secured" then your security people should be very happy to hear that you want to use SSH. SSH should already be running on the UNIX servers.
You can use ssh to execute any command on the remote system (that you're authorized to execute) instead of creating a login shell simply by appending the command to the end of the ssh command line (as described by the link above).

Resources