Correct exit code when no twistd.pid file

This commit is contained in:
meejah 2016-06-22 01:25:47 -06:00
parent e16b53817e
commit c4cd4db30e
2 changed files with 10 additions and 3 deletions

View File

@ -1,5 +1,6 @@
from __future__ import unicode_literals
import functools
import click
class ServerError(Exception):
def __init__(self, message, relay):
@ -47,7 +48,11 @@ class KeyFormatError(Exception):
class ReflectionAttack(Exception):
"""An attacker (or bug) reflected our outgoing message back to us."""
class UsageError(Exception):
# Click needs to receive click.UsageError instances to "do the right
# thing", which is print the error and exit -- perhaps it would be
# better just to re-export click.UsageError here? Or use
# click.UsageError throughout the codebase?
class UsageError(click.UsageError, Exception):
"""The programmer did something wrong."""
class WormholeClosedError(UsageError):

View File

@ -1,5 +1,6 @@
from __future__ import print_function, unicode_literals
import os, time
from ..errors import UsageError
from twisted.python import usage
from twisted.scripts import twistd
@ -38,8 +39,9 @@ def kill_server():
try:
f = open("twistd.pid", "r")
except EnvironmentError:
print("Unable to find twistd.pid . Is this really a server directory?")
return
raise UsageError(
"Unable to find 'twistd.pid' -- is this really a server directory?"
)
pid = int(f.read().strip())
f.close()
os.kill(pid, 15)