Systemd service to start program once on wifi

Hello. I am trying to create a systemd service to start Vesktop once the computer connects to wifi. But when I try this, I just get an exit-code failure. What am I doing wrong?

systemd.user.services.vesktop = {
  enable = true;
  description = "Vesktop service";
  after = [ "network-online.target" ];

  serviceConfig = {
    User = "user";
    wantedBy = [ "network-online.target" ];
    ExecStart = "vesktop %U --start-minimized";
    Restart = "on-failure";
    RestartSec = "5s";
  };
};

Various things are wrong with the config here:

The wantedBy should be a wants. (Reason is network-online.target isn’t pulled into the transaction by default)

The wants/wantedBy should be on the same level as after and not in serviceConfig

network-online.target doesn’t exist in the per- user instance of systemd. Only in the system instance. So you cant really do what you want here in the first place.

1 Like