[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: systemd: Exklusives Starten eines Service beim Booten



Hi,

On 11/22/2017 02:15 PM, Christoph Pleger wrote:
> Hallo,
> 
> kennt jemand eine Möglichkeit, mit systemd einen Service beim Booten so zu starten, dass keinesfalls gleichzeitig ein anderer Service gestartet wird, insbesondere kein neuer permanenter Prozess gestartet wird? Ich möchte einen Service anlegen, der beim Booten alle bis dahin vorhandenen Prozesse in eine neue cgroup verschiebt, was nicht wie gewünscht funktionieren kann, wenn während des Verschiebens neue Prozesse gestartet werden.
> 

Ich würde ein ein neues Target, welches nach multi-user.target geordnet
wird, erstellen.

# cat /etc/systemd/system/late.target
[Unit]
Description=Late Target running after multi-user
Requires=multi-user.target
After=multi-user.target
AllowIsolate=yes

Dann beim Service der alles verschieben soll ein WantedBy auf dieses
Target hinzufügen. Type=idle könnte auch noch helfen.
Für so ziemlich alle Standard Services ist multiuser das letzte Ziel,
Also wenn du danach startest und systemd auch noch sagst dass er dich
nur starten soll wenn grad keine andere unit aktiviert wird (Type=idle)
sollte das hinkommen.

Lesenswert:
https://www.mauras.ch/systemd-run-it-last.html#create-a-new-custom-target


Aber, ich habe ein leichten Verdacht das dass hier ein XY Problem ist.
Wenn du alles in eine CGroup packen willst nur um allen Prozessen eine
gewisse Ressource-Limitation aufzudrücken, verwende doch einfach
/etc/systemd/system.conf (oder /etc/systemd/system.conf.d/*.conf respektive)

> # man system.conf.d
> DefaultCPUAccounting=, DefaultBlockIOAccounting=,
> DefaultMemoryAccounting=, DefaultTasksAccounting=
>    Configure the default resource accounting settings, as configured
>    per-unit by CPUAccounting=, BlockIOAccounting=, MemoryAccounting=
>    and TasksAccounting=. See systemd.resource-control(5) for details
>    on the per-unit settings.  DefaultTasksAccounting= defaults to on,
>    the other three settings to off.
> [...]
> DefaultLimitCPU=, DefaultLimitFSIZE=, DefaultLimitDATA=,
> DefaultLimitSTACK=, DefaultLimitCORE=, DefaultLimitRSS=,
> DefaultLimitNOFILE=, DefaultLimitAS=, DefaultLimitNPROC=,
> DefaultLimitMEMLOCK=, DefaultLimitLOCKS=, DefaultLimitSIGPENDING=,
> DefaultLimitMSGQUEUE=, DefaultLimitNICE=, DefaultLimitRTPRIO=,
> DefaultLimitRTTIME=
>    These settings control various default resource limits for units.
>    See setrlimit(2) for details. The resource limit is possible to
>    specify in two formats, value to set soft and hard limits to the
>    same value, or soft:hard to set both limits individually (e.g.
>    DefaultLimitAS=4G:16G). Use the string infinity to configure no
>    limit on a specific resource. The multiplicative suffixes K
>    (=1024), M (=1024*1024) and so on for G, T, P and E may be used for
>    resource limits measured in bytes (e.g. DefaultLimitAS=16G). For
>    the limits referring to time values, the usual time units ms, s,
>    min, h and so on may be used (see systemd.time(7) for details).
>    Note that if no time unit is specified for DefaultLimitCPU= the
>    default unit of seconds is implied, while for DefaultLimitRTTIME=
>    the default unit of microseconds is implied. Also, note that the
>    effective granularity of the limits might influence their
>    enforcement. For example, time limits specified for
>    DefaultLimitCPU= will be rounded up implicitly to multiples of 1s.
>    These settings may be overridden in individual units using the
>    corresponding LimitXXX= directives. Note that these resource limits
>    are only defaults for units, they are not applied to PID 1 itself.


Vorteil davon, auch bei einem service restart, neuen service start, ...
sind die Prozesse gleich limitiert.


Beste Grüße,
Thomas



Reply to: