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:
Greg Taylor 2009-04-28 23:49:49 +00:00
parent b63bcc6132
commit 566a02b848
3 changed files with 112 additions and 28 deletions

View file

@ -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.