Selenium: shutDownSeleniumServer return 404 after upgrade from Selenium 2 to 3 (beta4)

Created on 30 Sep 2016  Â·  22Comments  Â·  Source: SeleniumHQ/selenium

Meta

OS: Ubuntu, docker
Selenium Version: 3.0.0-beta4 revision: 3169782
Browser: Chrome or Firefox

Expected Behavior

curl -s 'http://localhost:${NODE_PORT}/selenium-server/driver/?cmd=shutDownSeleniumServer'
#=> OKOK

Actual Behavior

curl -s 'http://localhost:${NODE_PORT}/selenium-server/driver/?cmd=shutDownSeleniumServer'
#=> 
<html><head><meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 404 </title></head><body><h2>HTTP ERROR: 404</h2>
<p>Problem accessing /selenium-server/driver/. Reason:
<pre>    Not Found</pre></p>
<hr /><i><small>Powered by Jetty://</small></i></body></html>

Steps to reproduce

  1. Upgrade selenium standalone jar from 2.53.1 to 3.0.0-beta4
  2. Try to /selenium-server/driver/?cmd=shutDownSeleniumServer

Most helpful comment

@elgalu actually, per my suggested approach we already have a servlet you can optionally include when running as a node. It's called LifecycleServlet..

$ java -jar selenium-server-standalone-3.0.0-beta4.jar -role node -servlet org.openqa.grid.web.servlet.LifecycleServlet

Then

$ curl -s http://{nodehost}:{nodeport}/extra/LifecycleServlet?action=shutdown

I tested this with beta4.

Closing this as a result. Please re-open if you see a need to.

All 22 comments

Adding some more info on this;

It seems this is a RC server command which is not supported in the Se3 leg-rc package.

  • To get past the 404, you need to add the leg-rc package to the CLASSPATH
  • Then, you'll see GET is not supported..
  • If you POST it, you'll get a 500 java.lang.NullPointerException

Personally, I don't see the need to support this command. Instead I think we should include (in our jar) an optional -servlet which adds the ability to shutdown a node via a HTTP request.

@elgalu actually, per my suggested approach we already have a servlet you can optionally include when running as a node. It's called LifecycleServlet..

$ java -jar selenium-server-standalone-3.0.0-beta4.jar -role node -servlet org.openqa.grid.web.servlet.LifecycleServlet

Then

$ curl -s http://{nodehost}:{nodeport}/extra/LifecycleServlet?action=shutdown

I tested this with beta4.

Closing this as a result. Please re-open if you see a need to.

Please explain how to stop the hub?

@zenonwch The LifecycleServlet mentioned in my previous comment is enabled by default on the hub. It's simply at a different path -- http://{hubhost}:{hubport}/lifecycle-manager/LifecycleServlet?action=shutdown. There is no change here from Se2 to Se3.

The recommended path to shutdown the hub does not appear to work for me with the 3.0.1 release of the standalone server.

If I try curl -s 'http://localhost:4444/lifecycle-manager/LifecycleServlet?action=shutdown' I get the help redirect page instead of the OKOK signal (and the server shutting down).

Am I missing something obvious?

Oh, yes, I was missing something obvious: I'm running the server without a role, which means I'm just running it as standalone. Is there an option for remote shutdown for folks running a standalone selenium server?

I'm experiencing the same problem as @eightyeighteyes. I want to use Selenium in my Ant build but I can't shut the standalone server down. Any ideas @mach6 ?

$ java -jar libs/selenium-server-standalone-3.0.1.jar  -role standalone -servlet org.openqa.grid.web.servlet.LifecycleServlet
Exception in thread "main" com.beust.jcommander.ParameterException: Unknown option: -servlet
    at com.beust.jcommander.JCommander.parseValues(JCommander.java:742)
    at com.beust.jcommander.JCommander.parse(JCommander.java:282)
    at com.beust.jcommander.JCommander.parse(JCommander.java:265)
    at com.beust.jcommander.JCommander.<init>(JCommander.java:210)
    at org.openqa.grid.selenium.GridLauncherV3$1.setConfiguration(GridLauncherV3.java:219)
    at org.openqa.grid.selenium.GridLauncherV3.buildLauncher(GridLauncherV3.java:147)
    at org.openqa.grid.selenium.GridLauncherV3.main(GridLauncherV3.java:73)

Edit: I'm now using selenium-server-2.53.1.zip which works fine

-servlet is not a valid parameter, when the role is 'standalone' (the default role).

There is not currently a built-in option to shutdown a standalone via a HTTP request.

Could there be a URL command? This is a pretty common way to shutdown a
server without having to hunt for the process.

On Dec 7, 2016 7:11 PM, "Doug Simmons" notifications@github.com wrote:

There is not currently a built-in option to shutdown a standalone via a
HTTP request.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/SeleniumHQ/selenium/issues/2852#issuecomment-265614441,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGS4Er3i7A-0HLGQ5iYiTCspgQrIpdK4ks5rF0sqgaJpZM4KKpfs
.

This is a pretty common way to shutdown a
server without having to hunt for the process.

as a possible workaround, you could find the PID and send it a SIGTERM..
If the standalone server is listening on the default port (4444):
lsof -t -i :4444 | xargs kill

@cgoldberg is there similar simple command for windows?

@zenonwch
for /f "tokens=5" %%a in ('netstat -aon ^| findstr ":4444"') do taskkill /F /PID %%a
How that breaks down:
for /f "tokens=5" %%a in () do - For each line from the output of the bracketed command, store the 5th column in %a and run the following command
'netstat -aon ^| findstr ":4444"' - Output all network process with PID, and filter by lines containing :4444
taskkill /F /PID %%a - Forcibly kill the process with the PID stored in %a.
I'm running this in a batch file. It seems you just can use %a instead of %%a when running in cmd.

@cgoldberg What if you don't have terminal access to the machine running the server? Or, a more likely scenario in my case, what if you're scripting the lifetime of the server, but want an alternative to a bare kill command in your teardown steps?

@eightyeighteyes sorry, I don't understand your question.

@cgoldberg Sure, let me be more clear:

I have unit tests that require the selenium server to run htmlunit. In the setup and teardown, I have methods to manage the server's lifecycle. The stop method sends sigterm to the server process, but if something gets in the way of that, my options are:

  • Get access to the machine, find the process on port 4444 and kill it (so VPN, SSH, lsof, and kill).
  • Script in lsof -t -i :4444 | xargs kill to the teardown (which seems undesirable).
    or, ideally
  • Use the URL command to shut the server down.

In my case, it's probably not a huge deal because I'm managing the server process during the test lifetime and it's unlikely something will interrupt my teardown. I'm just raising this issue because the URL command to shut down the selenium server is pretty ubiquitous. It comes up on stack overflow a bunch as the 'recommended' way to shut down a selenium server that you've lost the process for. Losing this functionality will probably impact a few people.

ok.. I think I understand now.

Get access to the machine

If you started the server, don't you already have access? If not, and you kill it remotely via URL, how are you expecting to start it up again?

Anyway, I would probably manage your server lifecycle with a separate process control system. Run a daemon process on the machine alongside the server which is responsible for monitoring/starting/stopping. Supervisor (http://supervisord.org/) is an example of such system, but there are many other options out there. This is a common pattern for managing servers that you need to keep running. In your test's setup and teardown, you could make a remote request to supervisor to start/stop your server (or just let it keep running and let supervisor restart it if it ever crashes).

If you started the server, don't you already have access?

Not necessarily: This is a process that's running in CI. As stated, I'm already managing the server process in the test cycle (via python's subprocess.Popen), but I appreciate the recommendation. Usually where I see this question come up is, someone has started the server process in a terminal and then closed the window.

I think the point I'm trying to push is that best practices are certainly the best answer for this issue, but the URL command is useful -- and among the top results for 'how do i shut down selenium server' -- for folks who have started the server and need to shut it down, but have lost track of the process. Just food for thought.

@marxjohnson thanks for your replay, but your solution requires different scripts for the different OS. :(

@cgoldberg, sorry, but I don't understand the reason of removing feature that was used by many users? I understand you wanted to do the best, but I saw a lot questions related this discussion - isn't it a sign to return old shutdown possibility back?

we will not be enabling this by default. I (and others) consider it a security hole that by default a selenium server can be shut down remotely, without any form of authentication on the server.

If one does wish to enable it, they can, although the url has changed.

Original details of how to do this https://github.com/SeleniumHQ/selenium/issues/2852#issuecomment-250841027

to reiterate the details, this works with 3.0.1 (when 3.0.2 comes out you can additionally specify -register false to stop it attempting to register with a hub).

java -jar selenium-server-standalone-3.0.1.jar -role node -servlet org.openqa.grid.web.servlet.LifecycleServlet -registerCycle 0 -port 4444

this is effectively the same as running the standalone-server in it's default "standalone" mode. But now you'll be able to shut it down with:

curl -s http://localhost:4444/extra/LifecycleServlet?action=shutdown

I consider this non-standard server behavior and mainly why we removed it from the server. I'm also going to restrict comments on this issue as I'd prefer this informational post to be the last one users see. If you'd like to discuss this more, I suggest posting on selenium-developers google group or talking to us on irc (freenode.net #selenium) or even slack

It should _also_ be noted that for -role hub, we will likely also disable LifecycleServlet by default in a future release. This change will bring consistency in this area, for all server types.

Was this page helpful?
0 / 5 - 0 ratings