We now have the ability via @service to list, start, and stop Twisted services. In this case, this just lets us start/stop IMC2 right now. As people write more services to plug in in the future, this may expand.
@service/list will show you the service names. If you see that your IMC has died due to an error, @service/start IMC2 will get it up and running again. I've also added an 'imcstatus' command to show more detailed information about your IMC2 connection.
This commit is contained in:
parent
b63bcc6132
commit
566a02b848
3 changed files with 112 additions and 28 deletions
|
|
@ -79,15 +79,31 @@ def cmd_imclist(command):
|
|||
source_object.emit_to(retval)
|
||||
GLOBAL_CMD_TABLE.add_command("imclist", cmd_imclist)
|
||||
|
||||
def cmd_imclistupdated(command):
|
||||
def cmd_imcstatus(command):
|
||||
"""
|
||||
Shows the list of cached games from the IMC2 Mud list.
|
||||
Shows some status information for your IMC2 connection.
|
||||
"""
|
||||
source_object = command.source_object
|
||||
# This manages our game's plugged in services.
|
||||
collection = command.session.server.service_collection
|
||||
# Retrieve the IMC2 service.
|
||||
service = collection.getServiceNamed('IMC2')
|
||||
|
||||
if service.running == 1:
|
||||
status_string = 'Running'
|
||||
else:
|
||||
status_string = 'Inactive'
|
||||
|
||||
# Build the output to emit to the player.
|
||||
retval = '-' * 50
|
||||
retval += '\n\r'
|
||||
retval += 'IMC Status\n\r'
|
||||
retval += ' * MUD Name: %s\n\r' % (settings.IMC2_MUDNAME)
|
||||
retval += ' * Status: %s\n\r' % (status_string)
|
||||
retval += ' * Debugging Mode: %s\n\r' % (settings.IMC2_DEBUG)
|
||||
retval += ' * IMC Network Address: %s\n\r' % (settings.IMC2_SERVER_ADDRESS)
|
||||
retval += ' * IMC Network Port: %s\n\r' % (settings.IMC2_SERVER_PORT)
|
||||
retval += '-' * 50
|
||||
|
||||
retval = 'Active MUDs on %s\n\r' % imc2_conn.IMC2_PROTOCOL_INSTANCE.network_name
|
||||
for name, mudinfo in IMC2_MUDLIST.mud_list.items():
|
||||
tdelta = time() - mudinfo.last_updated
|
||||
retval += ' %-20s %s\n\r' % (name, tdelta)
|
||||
source_object.emit_to(retval)
|
||||
GLOBAL_CMD_TABLE.add_command("imclistupdated", cmd_imclistupdated)
|
||||
GLOBAL_CMD_TABLE.add_command("imcstatus", cmd_imcstatus)
|
||||
|
|
@ -171,6 +171,71 @@ def cmd_home(command):
|
|||
GLOBAL_CMD_TABLE.add_command("home", cmd_home,
|
||||
priv_tuple=("genperms.tel_anywhere"))
|
||||
|
||||
def cmd_service(command):
|
||||
"""
|
||||
Service management system. Allows for the listing, starting, and stopping
|
||||
of services.
|
||||
"""
|
||||
pobject = command.source_object
|
||||
if "list" in command.command_switches:
|
||||
"""
|
||||
Just display the list of installed services and their status and die.
|
||||
"""
|
||||
pobject.emit_to('-' * 40)
|
||||
pobject.emit_to('Service Listing')
|
||||
for service in command.session.server.service_collection.services:
|
||||
# running is either 1 or 0, 1 meaning the service is running.
|
||||
if service.running == 1:
|
||||
status = 'Running'
|
||||
else:
|
||||
status = 'Inactive'
|
||||
pobject.emit_to(' * %s (%s)' % (service.name, status))
|
||||
pobject.emit_to('-' * 40)
|
||||
return
|
||||
|
||||
# This stuff is common to both start and stop switches.
|
||||
if "stop" in command.command_switches or "start" in command.command_switches:
|
||||
collection = command.session.server.service_collection
|
||||
try:
|
||||
service = collection.getServiceNamed(command.command_argument)
|
||||
except:
|
||||
pobject.emit_to('Invalid service name. This command is case-sensitive. See @service/list.')
|
||||
return
|
||||
|
||||
if "stop" in command.command_switches:
|
||||
"""
|
||||
Stopping a service gracefully closes it and disconnects any connections
|
||||
(if applicable).
|
||||
"""
|
||||
if service.running == 0:
|
||||
pobject.emit_to('That service is not currently running.')
|
||||
return
|
||||
# We don't want them killing main Evennia TCPServer services here. If
|
||||
# they'd like to nix a listening port, they need to do it through
|
||||
# settings.py and a restart.
|
||||
if service.name[:7] == 'Evennia':
|
||||
pobject.emit_to('You can not Evennia TCPServer services this way.')
|
||||
return
|
||||
pobject.emit_to('Stopping the %s service.' % service.name)
|
||||
service.stopService()
|
||||
return
|
||||
|
||||
if "start" in command.command_switches:
|
||||
"""
|
||||
Starts a service.
|
||||
"""
|
||||
if service.running == 1:
|
||||
pobject.emit_to('That service is already running.')
|
||||
return
|
||||
pobject.emit_to('Starting the %s service.' % service.name)
|
||||
service.startService()
|
||||
return
|
||||
|
||||
# If they don't provide any switches, let them know to do so.
|
||||
pobject.emit_to("You must specify a switch with @service. May be one of: list, start, stop")
|
||||
GLOBAL_CMD_TABLE.add_command("@service", cmd_service,
|
||||
priv_tuple=("genperms.process_control"))
|
||||
|
||||
def cmd_shutdown(command):
|
||||
"""
|
||||
Shut the server down gracefully.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue