Skip to content

Commit

Permalink
Merge pull request #16 from schmid-jn/feature/stop_prio
Browse files Browse the repository at this point in the history
feature/stop_prio
  • Loading branch information
fmessmer committed Aug 14, 2024
2 parents a793b7b + 50f69a2 commit 27f45ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ It is also helpful for local development to start multiple commands easily with

- [robmuxinator](#robmuxinator)
- [Installation](#installation)
- [Pip](#pip)
- [Nix](#nix)
- [Getting Started](#getting-started)
- [Usage](#usage)
- [Command Choices](#command-choices)
Expand All @@ -22,6 +24,8 @@ It is also helpful for local development to start multiple commands easily with

## Installation

### Pip

Install the robmuxinator with one simple command (execute in the `robmuxinator` package)
```
sudo pip install .
Expand Down Expand Up @@ -136,7 +140,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.
- `prio_stop: int` (optional, default: `prio`): Priority of stopping the session. Sessions with the same priority stop concurrently. Higher 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 +180,3 @@ This is s summary of useful commands for working with `tmux`.

## License
Apache License Version 2.0, January 2004

27 changes: 17 additions & 10 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 "prio_stop" in yaml_session:
self.prio_stop = int(yaml_session["prio_stop"])
else:
self.prio_stop = self.prio

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("\tprio_stop: {}".format(self.prio_stop))
print("\tlocked: {}".format(self._locked))


Expand Down Expand Up @@ -645,9 +651,9 @@ def order_sessions_by_key(sessions, key):
ordered_array = sorted(sessions, key=operator.attrgetter(key))
ordered_sessions = dict()
for s in ordered_array:
if not s.prio in ordered_sessions:
ordered_sessions[s.prio] = []
ordered_sessions[s.prio].append(s)
if not getattr(s, key) in ordered_sessions:
ordered_sessions[getattr(s, key)] = []
ordered_sessions[getattr(s, key)].append(s)
# returns a dict of arrays with prio as key and array of session with the same key(prio) as value
return ordered_sessions

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, "prio_stop")

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 27f45ff

Please sign in to comment.