16 Oct 2023 |
Artturin | l0b0:
$ bash -c "exit 3"
$ echo $?
3
$ systemd-run --user bash -c "exit 3"
Running as unit: run-r87bbe16cbe554be0965fc147cc7ecc81.service
$ systemctl show --user run-r87bbe16cbe554be0965fc147cc7ecc81.service --property="ExecMainStatus"
ExecMainStatus=3
| 05:48:08 |
l0b0 | In reply to @artturin:matrix.org
l0b0:
$ bash -c "exit 3"
$ echo $?
3
$ systemd-run --user bash -c "exit 3"
Running as unit: run-r87bbe16cbe554be0965fc147cc7ecc81.service
$ systemctl show --user run-r87bbe16cbe554be0965fc147cc7ecc81.service --property="ExecMainStatus"
ExecMainStatus=3
Oh, nifty! Can I control the unit name, or do I have to parse stdout to get it? | 05:48:56 |
l0b0 | In reply to @artturin:matrix.org
l0b0:
$ bash -c "exit 3"
$ echo $?
3
$ systemd-run --user bash -c "exit 3"
Running as unit: run-r87bbe16cbe554be0965fc147cc7ecc81.service
$ systemctl show --user run-r87bbe16cbe554be0965fc147cc7ecc81.service --property="ExecMainStatus"
ExecMainStatus=3
* Oh, nifty! ~Can I control the unit name, or do I have to parse stdout to get it?~ I'll just check… | 05:49:10 |
Artturin | you can with -u | 05:49:18 |
Artturin | according to help | 05:49:28 |
Artturin | Maybe you can wait with https://github.com/NixOS/nixpkgs/blob/master/nixos/lib/test-driver/test_driver/machine.py#L506 | 05:49:51 |
Artturin | require_unit_state | 05:49:54 |
Artturin | Waiting for a failed | 05:50:22 |
Artturin | Seems you don't even have to use the systemd-run command but can do it in python https://github.com/NixOS/nixpkgs/blob/4ef910059530798af9f36376f812488edf39d751/nixos/lib/test-driver/test_driver/machine.py#L461 | 05:52:33 |
Artturin | info = self.get_unit_info(unit, user)
if info["ExecMainStatus"] == "123":
| 05:53:14 |
Artturin | * check the check_active in wait_for_unit
info = self.get_unit_info(unit, user)
if info["ExecMainStatus"] == "123":
| 05:53:43 |
l0b0 | I'm running into something odd while trying this:
server: must succeed: systemd-run --unit=ssh-audit.service --user /nix/store/cqsj9477bs0r92cnvdbnhxhgp3csmzkl-ssh-audit-2.9.0/bin/ssh-audit --client-audit --port=2222 server # Failed to connect to bus: No medium found
| 06:01:38 |
Artturin | The environment is almost completely cleared | 06:04:27 |
Artturin | In reply to @vengmark2:matrix.org
I'm running into something odd while trying this:
server: must succeed: systemd-run --unit=ssh-audit.service --user /nix/store/cqsj9477bs0r92cnvdbnhxhgp3csmzkl-ssh-audit-2.9.0/bin/ssh-audit --client-audit --port=2222 server # Failed to connect to bus: No medium found
Oh that's coming from systemd https://github.com/search?q=%2FFailed+to+connect+to+bus%3A+No+medium%2F&type=code | 06:06:52 |
Artturin | Try no --user | 06:07:22 |
Artturin | Not a good error :/ | 06:08:18 |
l0b0 | I really wish there was a wait_for_unit_state … | 06:10:03 |
Artturin | Maybe a new arg to wait_for_unit | 06:11:39 |
Artturin | failState successState | 06:12:13 |
l0b0 | Weird. I just tried this:
service_name = "ssh-audit.service"
${serverName}.succeed(f"systemd-run --unit={service_name} ${pkgs.ssh-audit}/bin/ssh-audit --client-audit --port=${toString sshAuditPort}")
${serverName}.wait_for_unit(service_name)
${clientName}.execute(
f"ssh {ssh_options} -i privkey.snakeoil -p ${toString sshAuditPort} ${sshUsername}@server true",
check_return=False,
timeout=10
)
${serverName}.succeed(f"exit $(systemctl show --property=ExecMainStatus --value {service_name})")
Couldn't get it to fail when the configuration was bad.
| 06:15:40 |
Artturin | Btw it's possible to add env vars to the systemd-run env
dbus-update-activation-environment --systemd PATH this would add the PATH
| 06:17:55 |
Artturin | * Btw it's possible to add env vars to the systemd-run env
dbus-update-activation-environment --systemd PATH this would add the PATH, the sway module has dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP
| 06:18:27 |
Artturin | In reply to @vengmark2:matrix.org
Weird. I just tried this:
service_name = "ssh-audit.service"
${serverName}.succeed(f"systemd-run --unit={service_name} ${pkgs.ssh-audit}/bin/ssh-audit --client-audit --port=${toString sshAuditPort}")
${serverName}.wait_for_unit(service_name)
${clientName}.execute(
f"ssh {ssh_options} -i privkey.snakeoil -p ${toString sshAuditPort} ${sshUsername}@server true",
check_return=False,
timeout=10
)
${serverName}.succeed(f"exit $(systemctl show --property=ExecMainStatus --value {service_name})")
Couldn't get it to fail when the configuration was bad.
All the outputted thing should be in the output | 06:20:24 |
Artturin | did it print the expected output but just didn't fail | 06:20:34 |
l0b0 | OIC, ${serverName}.wait_for_unit(service_name) doesn't wait long enough, so the next line just never talks to ssh-audit . | 06:22:36 |
l0b0 | I think I might still need the sleep(5) then. | 06:23:00 |
Artturin | hm yeah it just waits for active | 06:23:19 |
l0b0 | Because there's just no way to check that the port is open without shutting down ssh-audit . | 06:23:28 |
l0b0 | Yay, it worked! This is something I've been hoping to be able to do for years. Thank you, Artturin ! | 07:05:48 |
Artturin | l0b0: That tests looks like it could be added to nixpkgs | 07:45:32 |