From 059b44893223d41cfbf3132fb9de36df10ea0be5 Mon Sep 17 00:00:00 2001 From: Jarrod Johnon Date: Tue, 18 Nov 2014 17:02:54 -0500 Subject: [PATCH] Cleanly handle stop/restart when not running Previously some rather uncomfortable looking output would be emitted at someone trying to restart confluent if not running. Be nicer and recognize when service is not running and a stop attempt is made. --- confluent_server/confluent/sockapi.py | 7 +++++++ confluent_server/sysvinit/confluent | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/confluent_server/confluent/sockapi.py b/confluent_server/confluent/sockapi.py index d8895d6e..1e8b3795 100644 --- a/confluent_server/confluent/sockapi.py +++ b/confluent_server/confluent/sockapi.py @@ -19,6 +19,7 @@ # It implement unix and tls sockets # +import atexit import os import pwd import stat @@ -222,6 +223,11 @@ def _tlsstartup(cnn): server_side=True) sessionhdl(cnn, authname) +def removesocket(): + try: + os.remove("/var/run/confluent/api.sock") + except OSError: + pass def _unixdomainhandler(): unixsocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) @@ -233,6 +239,7 @@ def _unixdomainhandler(): os.chmod("/var/run/confluent/api.sock", stat.S_IWOTH | stat.S_IROTH | stat.S_IWGRP | stat.S_IRGRP | stat.S_IWUSR | stat.S_IRUSR) + atexit.register(removesocket) unixsocket.listen(5) while True: cnn, addr = unixsocket.accept() diff --git a/confluent_server/sysvinit/confluent b/confluent_server/sysvinit/confluent index 8423e313..6661a308 100755 --- a/confluent_server/sysvinit/confluent +++ b/confluent_server/sysvinit/confluent @@ -21,8 +21,10 @@ fi case $1 in restart) - echo -n 'Stopping Confluent ' - /opt/confluent/bin/confetty shutdown / + if [ -S /var/run/confluent/api.sock ]; then + echo -n 'Stopping Confluent ' + /opt/confluent/bin/confetty shutdown / + fi echo -n 'Starting Confluent ' /opt/confluent/bin/confluent $LOG_SUCCESS @@ -34,7 +36,9 @@ case $1 in ;; stop) echo -n 'Stopping Confluent ' - /opt/confluent/bin/confetty shutdown / + if [ -S /var/run/confluent/api.sock ]; then + /opt/confluent/bin/confetty shutdown / + fi $LOG_SUCCESS ;; esac