New "-k" command-line parameter to shutdown an existing local Luminotes server (if allowed by the configuration).
This commit is contained in:
parent
0a645090c7
commit
3e7cd20d43
|
@ -12,6 +12,7 @@ settings = {
|
|||
"luminotes.launch_browser": True,
|
||||
"luminotes.db_host": None, # use local SQLite database
|
||||
"luminotes.auto_login_username": "desktopuser",
|
||||
"luminotes.allow_shutdown_command": True, # used to stop the process during uninstall
|
||||
"luminotes.rate_plans": [
|
||||
{
|
||||
"name": "desktop",
|
||||
|
|
|
@ -367,6 +367,16 @@ class Root( object ):
|
|||
response = u"pong",
|
||||
)
|
||||
|
||||
@expose( view = Json )
|
||||
def shutdown( self ):
|
||||
# this is typically only allowed in the desktop configuration
|
||||
if self.__settings[ u"global" ].get( u"luminotes.allow_shutdown_command" ) is not True:
|
||||
return dict()
|
||||
|
||||
cherrypy.server.stop()
|
||||
|
||||
return dict()
|
||||
|
||||
def _cp_on_http_error( self, status, message ):
|
||||
"""
|
||||
CherryPy HTTP error handler, used to display page not found and generic error pages.
|
||||
|
|
|
@ -482,6 +482,28 @@ class Test_root( Test_controller ):
|
|||
|
||||
assert result.get( "response" ) == u"pong"
|
||||
|
||||
def test_shutdown( self ):
|
||||
self.settings[ u"global" ][ u"luminotes.allow_shutdown_command" ] = True
|
||||
|
||||
assert cherrypy.server._is_ready() is True
|
||||
result = self.http_get( "/shutdown" )
|
||||
|
||||
assert cherrypy.server._is_ready() is False
|
||||
|
||||
def test_shutdown_disallowed_explicitly( self ):
|
||||
self.settings[ u"global" ][ u"luminotes.allow_shutdown_command" ] = False
|
||||
|
||||
assert cherrypy.server._is_ready() is True
|
||||
result = self.http_get( "/shutdown" )
|
||||
|
||||
assert cherrypy.server._is_ready() is True
|
||||
|
||||
def test_shutdown_disallowed_implicitly( self ):
|
||||
assert cherrypy.server._is_ready() is True
|
||||
result = self.http_get( "/shutdown" )
|
||||
|
||||
assert cherrypy.server._is_ready() is True
|
||||
|
||||
def test_404( self ):
|
||||
result = self.http_get( "/four_oh_four" )
|
||||
|
||||
|
|
10
luminotes.py
10
luminotes.py
|
@ -47,11 +47,19 @@ def main( args ):
|
|||
|
||||
launch_browser = cherrypy.config.configMap[ u"global" ].get( u"luminotes.launch_browser" )
|
||||
|
||||
# check to see if the server is already running
|
||||
socket.setdefaulttimeout( INITIAL_SOCKET_TIMEOUT_SECONDS )
|
||||
server_url = u"http://localhost:%d/" % cherrypy.config.configMap[ u"global" ].get( u"server.socket_port" )
|
||||
server_present = True
|
||||
|
||||
# if requested, attempt to shutdown an existing server and exit
|
||||
if args and "-k" in args:
|
||||
try:
|
||||
urllib.urlopen( "%sshutdown" % server_url )
|
||||
except urllib.URLError:
|
||||
pass
|
||||
sys.exit( 0 )
|
||||
|
||||
# check to see if the server is already running
|
||||
try:
|
||||
urllib.urlopen( "%sping" % server_url )
|
||||
except urllib.URLError:
|
||||
|
|
Reference in New Issue