Systemd/User Services/ru: Difference between revisions
|  Created page with "В NixOS пользовательский сервис может быть выражен с помощью {{ic|systemd.user.services.<name>}}, как описано здесь: https://search.nixos.org/options?query=systemd.user.services." |  Created page with "Это может быть полезно, если вы хотите, чтобы пользователь мог запускать, останавливать и перезапускать свой собственный экземпляр службы без необходимости делать его sudoer." | ||
| Line 3: | Line 3: | ||
| </div> | </div> | ||
| В NixOS пользовательский сервис может быть выражен с помощью {{ic|systemd.user.services.<name>}}, как описано здесь: https://search.nixos.org/options?query=systemd.user.services. | В NixOS пользовательский сервис может быть выражен с помощью {{ic|systemd.user.services.<name>}}, как описано здесь: https://search.nixos.org/options?query=systemd.user.services. | ||
| Это может быть полезно, если вы хотите, чтобы пользователь мог запускать, останавливать и перезапускать свой собственный экземпляр службы без необходимости делать его sudoer. | |||
| <div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Here is an example: | Here is an example: | ||
Revision as of 16:52, 5 August 2024
Systemd supports running a separate instance of systemd for a given user, allowing the user to control their own services. See here for more information: https://wiki.archlinux.org/title/Systemd/User
В NixOS пользовательский сервис может быть выражен с помощью systemd.user.services.<name>, как описано здесь: https://search.nixos.org/options?query=systemd.user.services.
Это может быть полезно, если вы хотите, чтобы пользователь мог запускать, останавливать и перезапускать свой собственный экземпляр службы без необходимости делать его sudoer.
Here is an example:
systemd.user.services.my-cool-user-service = {
  enable = true;
  after = [ "network.target" ];
  wantedBy = [ "default.target" ];
  description = "Мой Классный Пользовательский Сервис";
  serviceConfig = {
      Type = "simple";
      ExecStart = ''/my/cool/user/service'';
  };
};
By default, user services will be stopped when the user logs out and will start again when the user logs back in due to us setting wantedBy = [ "default.target" ] in the example.
Keeping user services running after logout
If you need a user service to stay running after a user logs out, you need to enable "lingering" by setting users.users.<username>.linger = true;
You'll also likely want to change to wantedBy = [ "multi-user.target" ]; so the service starts at boot time.
