From c4d494db878d0dcabc125170324634625fbe33ba Mon Sep 17 00:00:00 2001 From: Christian Rotzoll Date: Tue, 2 Apr 2019 03:00:24 +0100 Subject: [PATCH] add try catch --- home.admin/config.scripts/internet.sshtunnel.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/home.admin/config.scripts/internet.sshtunnel.py b/home.admin/config.scripts/internet.sshtunnel.py index dc87da3..402a7e3 100755 --- a/home.admin/config.scripts/internet.sshtunnel.py +++ b/home.admin/config.scripts/internet.sshtunnel.py @@ -39,7 +39,10 @@ WantedBy=multi-user.target if sys.argv[1] == "on": # check if already running - already_running = subprocess.check_output("systemctl is-enabled %s" % (SERVICENAME) ,shell=True, universal_newlines=True) + try: + already_running = subprocess.check_output("systemctl is-enabled %s" % (SERVICENAME) ,shell=True, universal_newlines=True) + except subprocess.CalledProcessError as e: + already_running = "disabled" if str(already_running).count("enabled") > 0: print("already ON - run 'internet.sshtunnel.py off' first") sys.exit(1) @@ -139,7 +142,10 @@ if sys.argv[1] == "on": elif sys.argv[1] == "off": # check if already disabled - alreadyRunning = subprocess.check_output("systemctl is-enabled %s" % (SERVICENAME) ,shell=True, universal_newlines=True) + try: + alreadyRunning = subprocess.check_output("systemctl is-enabled %s" % (SERVICENAME) ,shell=True, universal_newlines=True) + except subprocess.CalledProcessError as e: + already_running = "disabled" if str(alreadyRunning).count("enabled") == 0: print("Was already OFF") sys.exit(0)