microvm.nix icon indicating copy to clipboard operation
microvm.nix copied to clipboard

added option to configure startupTimeout for vms

Open GlennWSo opened this issue 8 months ago • 5 comments

should resolve issue #317

Make the default timeout for vm starup an option

GlennWSo avatar Apr 24 '25 07:04 GlennWSo

Changed to draft, because i have not yet confirmed if this will resolve the issue

GlennWSo avatar Apr 24 '25 08:04 GlennWSo

While the option is sensible, the default of 90s is already quite high. VMs should boot within a minute. However, performance has degraded sometime in the last year and we're still figuring out the reason.

astro avatar Apr 24 '25 12:04 astro

Yeah, this patchset does feel like treating the symptom not the cause.

In my case the VM has booted, but I can login with ssh.

But it restarts anyways because nextcloud-setup.service can take a long time to finnish when it needs to stuff like reindexing a database.

It seems to me that the deeper issue is that vmrunner does not differentiate between "booted" and "all oneshoot services on startup being completed"

GlennWSo avatar Apr 25 '25 06:04 GlennWSo

I am using this as test systemds to provoke the unwanted reboot.

# in the guest vm conf
  systemd.services."expensive-oneshot" = {
    enable = true;
    after = ["postgresql.service"];
    requires = ["postgresql.service"];
    before = ["long-derp.service"];
    wantedBy = ["multi-user.target"];
    script = ''
      #!/usr/bin/env bash
      echo running dummy script
      for i in {0..200}
      do
        sleep 1
        echo "Number: $i of 200"
      done

    '';
    serviceConfig = {
      Type = "oneshot";
    };
  };

  systemd.services."long-derp" = {
    enable = true;
    wantedBy = ["multi-user.target"];
    script = ''
      #!/bin/bash
      while true :
      do
      echo "Dont mind me"
      sleep 1
      done
    '';
    serviceConfig = {
      Type = "simple";
    };
  };

GlennWSo avatar Apr 25 '25 09:04 GlennWSo

So i conculude if

I am using this as test systemds to provoke the unwanted reboot.

# in the guest vm conf
  systemd.services."expensive-oneshot" = {
    enable = true;
    after = ["postgresql.service"];
    requires = ["postgresql.service"];
    before = ["long-derp.service"];
    wantedBy = ["multi-user.target"];
    script = ''
      #!/usr/bin/env bash
      echo running dummy script
      for i in {0..200}
      do
        sleep 1
        echo "Number: $i of 200"
      done

    '';
    serviceConfig = {
      Type = "oneshot";
    };
  };

  systemd.services."long-derp" = {
    enable = true;
    wantedBy = ["multi-user.target"];
    script = ''
      #!/bin/bash
      while true :
      do
      echo "Dont mind me"
      sleep 1
      done
    '';
    serviceConfig = {
      Type = "simple";
    };
  };

With the default timeout setting this vm configuration gets stuck in endless rebooting. I assume this is because all services wanted multi-user.target is not reached in time.

But using the new proposed setting, I can give my vms enough time to complete my dummy setup service.

 microvm = {

    host.startupTimeout = 500;

}

I have tested and confirmed that this solves #317 I will mark this pr as ready for merge.

Do you want me to write some test, or is "trust me bro" good enough?

GlennWSo avatar Apr 25 '25 09:04 GlennWSo

To speed things up, I added some review comments :)

SuperSandro2000 avatar Jul 17 '25 21:07 SuperSandro2000