Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout command just before dispatch #380

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,22 @@ def _ensure_reconcile_timer_is_active(self) -> None:
logger.error("Reconciliation event timer is not activated")
self._set_reconcile_timer()

@staticmethod
def _log_juju_processes() -> None:
"""Log the running Juju processes.

Log all processes with 'juju' in the command line.
"""
try:
processes, _ = execute_command(
["ps", "afuwwx"],
check_exit=True,
)
juju_processes = "\n".join(line for line in processes.splitlines() if "juju" in line)
logger.info("Juju processes: %s", juju_processes)
except SubprocessError:
logger.exception("Failed to get Juju processes")

@catch_charm_errors
def _on_upgrade_charm(self, _: UpgradeCharmEvent) -> None:
"""Handle the update of charm."""
Expand Down Expand Up @@ -898,6 +914,7 @@ def _on_update_dependencies_action(self, event: ActionEvent) -> None:
def _on_update_status(self, _: UpdateStatusEvent) -> None:
"""Handle the update of charm status."""
self._ensure_reconcile_timer_is_active()
self._log_juju_processes()

@catch_charm_errors
def _on_stop(self, _: StopEvent) -> None:
Expand Down
2 changes: 1 addition & 1 deletion templates/dispatch-event.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Description=Dispatch the {{event}} event on {{unit}}
[Service]
Type=oneshot
# For juju 3 and juju 2 compatibility. The juju-run binary was renamed to juju-exec for juju 3.
ExecStart=/usr/bin/timeout "{{timeout}}" /usr/bin/run-one /usr/bin/bash -c '/usr/bin/juju-exec "{{unit}}" "JUJU_DISPATCH_PATH={{event}} ./dispatch" || /usr/bin/juju-run "{{unit}}" "JUJU_DISPATCH_PATH={{event}} ./dispatch"'
ExecStart=/usr/bin/timeout "{{timeout}}" /usr/bin/run-one /usr/bin/bash -c '/usr/bin/juju-exec "{{unit}}" "JUJU_DISPATCH_PATH={{event}} /usr/bin/timeout {{timeout}} ./dispatch" || /usr/bin/juju-run "{{unit}}" "JUJU_DISPATCH_PATH={{event}} /usr/bin/timeout {{timeout}} ./dispatch"'

[Install]
WantedBy=multi-user.target
Loading