#26 Le 23/03/2021, à 13:06
- boubchat
Re : Script qui ne se lance pas à l'extinction du PC
Merci de ces précisions, effectivement j'ai enlevé le shutdown qui ne servait à rien.
Cependant qq chose reste bizarre : maintenant que les services fonctionnent à l'extinction et au démarrage (création des fichiers Hello.txt et auRevoir.txt), impossible de lancer les services avec le code suivant:
systemctl start PourDemarrage.service
systemctl start PourExtinction.service
est-ce que c'est à cause des wantedBy ?
(Les services et scripts sont ceux mentionnés au dessus)
est-ce que vous avez une idée? Merci encore
Hors ligne
#27 Le 23/03/2021, à 13:37
- MicP
Re : Script qui ne se lance pas à l'extinction du PC
…Il sera lancé mais risque de ne pas avoir le temps de s'exécuter avant l'extinction …
Si tu as mis une directive Before, toutes les unités qui sont dans la liste ne seront lancées
qu'après que l'unité ait terminé son travail.
Voir : freedesktop.org -> systemd.unit — Unit configuration
…
Before=, After=These two settings expect a space-separated list of unit names. They may be specified more than once, in which case dependencies for all listed names are created.
Those two settings configure ordering dependencies between units. If unit foo.service contains the setting Before=bar.service and both units are being started, bar.service's start-up is delayed until foo.service has finished starting up. After= is the inverse of Before=, i.e. while Before= ensures that the configured unit is started before the listed unit begins starting up, After= ensures the opposite, that the listed unit is fully started up before the configured unit is started.
When two units with an ordering dependency between them are shut down, the inverse of the start-up order is applied. I.e. if a unit is configured with After= on another unit, the former is stopped before the latter if both are shut down. Given two units with any ordering dependency between them, if one unit is shut down and the other is started up, the shutdown is ordered before the start-up. It doesn't matter if the ordering dependency is After= or Before=, in this case. It also doesn't matter which of the two is shut down, as long as one is shut down and the other is started up; the shutdown is ordered before the start-up in all cases. If two units have no ordering dependencies between them, they are shut down or started up simultaneously, and no ordering takes place. It depends on the unit type when precisely a unit has finished starting up. Most importantly, for service units start-up is considered completed for the purpose of Before=/After= when all its configured start-up commands have been invoked and they either failed or reported start-up success. Note that this does includes ExecStartPost= (or ExecStopPost= for the shutdown case).
Note that those settings are independent of and orthogonal to the requirement dependencies as configured by Requires=, Wants=, Requisite=, or BindsTo=. It is a common pattern to include a unit name in both the After= and Wants= options, in which case the unit listed will be started before the unit that is configured with these options.
Note that Before= dependencies on device units have no effect and are not supported. Devices generally become available as a result of an external hotplug event, and systemd creates the corresponding device unit without delay.
…
Hors ligne
#28 Le 23/03/2021, à 13:49
- boubchat
Re : Script qui ne se lance pas à l'extinction du PC
Merci de ta réponse. Pas de before, j'avais enlevé les after mais sans résultat...
Et là, la lumière est apparue. La tâche était toujours active en arrière plan et du coup elle ne se lançait pas puisque toujours active. Il a fallu que je la stop puis la restart pour qu'elle marche...
Voila...
Dernière modification par boubchat (Le 23/03/2021, à 13:53)
Hors ligne