Skip to content

Commit

Permalink
merge stop and remove config file into reset() function
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanhphan1147 committed Feb 9, 2024
1 parent e11db0b commit b503a54
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/agent_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ def _on_agent_relation_changed(self, _: ops.RelationChangedEvent) -> None:
def _on_agent_relation_departed(self, _: ops.RelationDepartedEvent) -> None:
"""Handle agent relation departed event."""
try:
self.jenkins_agent_service.stop()
self.jenkins_agent_service.reset()
except service.ServiceStopError:
self.charm.unit.status = ops.BlockedStatus("Error stopping the agent service")
return
self.jenkins_agent_service.clear_service_configuration()
self.charm.unit.status = ops.BlockedStatus("Waiting for config/relation.")
7 changes: 2 additions & 5 deletions src/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ def restart(self) -> None:
if not self._startup_check():
raise ServiceRestartError("Error waiting for the agent service to start")

def stop(self) -> None:
"""Stop the agent service.
def reset(self) -> None:
"""Stop the agent service and clear its configuration file.
Raises:
ServiceStopError: if systemctl stop returns a non-zero exit code.
Expand All @@ -175,9 +175,6 @@ def stop(self) -> None:
except systemd.SystemdError as exc:
logger.error("service %s failed to stop", AGENT_SERVICE_NAME)
raise ServiceStopError(f"service {AGENT_SERVICE_NAME} failed to stop") from exc

def clear_service_configuration(self) -> None:
"""Clear the service's configuration file."""
config_file = Path(f"{SYSTEMD_SERVICE_CONF_DIR}/override.conf")
config_file.unlink(missing_ok=True)

Expand Down

0 comments on commit b503a54

Please sign in to comment.