Skip to content

Commit

Permalink
add stop prio feature
Browse files Browse the repository at this point in the history
  • Loading branch information
schmid-jn committed Aug 12, 2024
1 parent a793b7b commit 84a674e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ It is also helpful for local development to start multiple commands easily with

- [robmuxinator](#robmuxinator)
- [Installation](#installation)
- [Nix](#nix)
- [Getting Started](#getting-started)
- [Usage](#usage)
- [Command Choices](#command-choices)
Expand Down Expand Up @@ -136,7 +137,8 @@ sessions:
- `host: string` (optional, default: hostname of localhost): Target host of the `tmux` session.
- `user: string` (optional, default: robot): Target user of the `tmux` session.
- `wait_for_core: bool` (optional, default: true): Starts the session only after `roscore` is available.
- `prio: int` (optional, default: 10): Priority of the session. Sessions with the same priority start concurrently. Smaller numbers have higher priority.
- `prio: int` (optional, default: 10): Priority of starting the session. Sessions with the same priority start concurrently. Smaller numbers have higher priority.
- `stop_prio: int` (optional, default: 10): Priority of stopping the session. Sessions with the same priority stop concurrently. Smaller numbers have higher priority.
- `locked: bool` (optional, default: false): Locked sessions won't be closed on `stop` or `restart` (only if forced).
- `pre_condition: string` (optional): Bash command used as a condition that must be fulfilled before the session can start.

Expand Down Expand Up @@ -175,4 +177,3 @@ This is s summary of useful commands for working with `tmux`.

## License
Apache License Version 2.0, January 2004

21 changes: 14 additions & 7 deletions robmuxinator/robmuxinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,11 @@ def __init__(self, ssh_client, session_name, yaml_session, envs=None) -> None:
else:
self.prio = 10

if "stop_prio" in yaml_session:
self.stop_prio = int(yaml_session["stop_prio"])
else:
self.stop_prio = 10

if "locked" in yaml_session:
self._locked = yaml_session["locked"]
else:
Expand Down Expand Up @@ -568,6 +573,7 @@ def dump(self):
print("\tcommand: {}".format(self._command))
print("\tpre_condition: {}".format(self._pre_condition))
print("\tprio: {}".format(self.prio))
print("\tstop_prio: {}".format(self.stop_prio))
print("\tlocked: {}".format(self._locked))


Expand Down Expand Up @@ -919,33 +925,34 @@ def main():
logger.error(e)
sys.exit()

ordered_sessions = order_sessions_by_key(sessions, "prio")
ordered_sessions_start = order_sessions_by_key(sessions, "prio")
ordered_sessions_stop = order_sessions_by_key(sessions, "stop_prio")

if command == "start":
# wait for other hosts
if len(hosts) > 1 and not wait_for_hosts(hosts, timeout):
sys.exit()
start_sessions(ordered_sessions)
start_sessions(ordered_sessions_start)
logger.info(
"starting took {} secs".format((datetime.now() - start).total_seconds())
)
elif command == "stop":
stop_sessions(ordered_sessions, args.force)
stop_sessions(ordered_sessions_stop, args.force)
logger.info(
"stopping took {} secs".format((datetime.now() - start).total_seconds())
)
elif command == "restart":
stop_sessions(ordered_sessions, args.force)
start_sessions(ordered_sessions)
stop_sessions(ordered_sessions_stop, args.force)
start_sessions(ordered_sessions_start)
logger.info(
"restart took {} secs".format((datetime.now() - start).total_seconds())
)
elif command == "shutdown":
pre_shutdown_commands(yaml_content)
stop_sessions(ordered_sessions, True)
stop_sessions(ordered_sessions_stop, True)
shutdown_system(hosts, timeout)
elif command == "reboot":
pre_reboot_commands(yaml_content)
pre_shutdown_commands(yaml_content)
stop_sessions(ordered_sessions, True)
stop_sessions(ordered_sessions_stop, True)
shutdown_system(hosts, timeout)

0 comments on commit 84a674e

Please sign in to comment.