Commit a6c92979 authored by segfault's avatar segfault

Print warning instead of raising exception if service is already stopped

We caught and ignored the exception in any case anyway, so a warning
seems more appropriate and reduces complexity.
parent 61f27220
......@@ -6,10 +6,6 @@ class ServiceAlreadyStartedError(Exception):
pass
class ServiceAlreadyStoppedError(Exception):
pass
class ServiceAlreadyInstalledError(Exception):
pass
......
......@@ -4,7 +4,6 @@ from logging import getLogger
from onionkit import _
from onionkit.option import OnionServiceOption
from onionkit.exceptions import ServiceAlreadyStoppedError
from onionkit import STATE_DIR, TEMP_STATE_DIR
......@@ -40,12 +39,8 @@ class Persistence(OnionServiceOption):
logger.info("Making service %r persistent", self.service.Name)
# Ensure service is stopped
was_running = False
try:
self.service.Stop()
was_running = True
except ServiceAlreadyStoppedError:
pass
was_running = self.service.IsRunning
self.service.Stop()
# Unmount bind mounts, because we are going to move the source files
self.service.unmount()
......@@ -67,12 +62,8 @@ class Persistence(OnionServiceOption):
logger.info("Removing persistence of service %r", self.service.Name)
# Ensure service is stopped
was_running = False
try:
self.service.Stop()
was_running = True
except ServiceAlreadyStoppedError:
pass
was_running = self.service.IsRunning
self.service.Stop()
# Unmount bind mounts, because we are going to move the source files
self.service.unmount()
......
......@@ -23,7 +23,6 @@ from onionkit.options.allow_lan import AllowLAN
from onionkit.exceptions import ServiceNotInstalledError
from onionkit.exceptions import ServiceAlreadyStartedError
from onionkit.exceptions import ServiceAlreadyStoppedError
from onionkit.systemd import SystemdManager
from onionkit.tor import TorManager
......@@ -216,9 +215,6 @@ class OnionService(DBusObject, metaclass=abc.ABCMeta):
def Stop(self):
try:
logger.info("Stopping service %r", self.Name)
if not self.IsRunning and not self.IsPublished:
raise ServiceAlreadyStoppedError("Service %r is already stopped" % self.Name)
self.Status = Status.STOPPING
if self.IsRunning:
......@@ -228,8 +224,6 @@ class OnionService(DBusObject, metaclass=abc.ABCMeta):
self.tor.stop_hidden_service(self.Address)
self.Status = Status.STOPPED
except ServiceAlreadyStoppedError:
raise
except Exception:
logger.warning("Handling error in service.Stop")
self.Status = Status.ERROR
......@@ -238,11 +232,7 @@ class OnionService(DBusObject, metaclass=abc.ABCMeta):
def RegenerateAddress(self):
logger.info("Generating new address")
was_published = self.IsPublished
try:
self.Stop()
except ServiceAlreadyStoppedError:
pass
self.Stop()
self.private_key.create()
self.Address = self.private_key.derive_onion_address()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment