Be able to give lock to son processes detached by systemctl #367
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Following the changes in the lock system in Moulinette, it was noticed that it causes an issue for services that need to run yunohost command. Basically this kind of situation :
Process 10 is detached from process 6, therefore the lock taken by 5 cannot be used by 11...
This kind of situation happens at least in three different context :
Solution
The proposed solution is that, everytime we have to restart a service which needs to be able to run yunohost commands, we launch the service/systemctl command in background, get the PID of the command launched by systemctl (using
systemctl show
), and add a lock for it to be able to run yunohost commands. For this, we need YunoHost/moulinette#154A flag is set in services.yml (
need_lock: true
) to define which services need the lock.With this design, only the process currently having the lock (A) gives the lock to another process (B). A waits for B to ends its execution, hence there's no issue for concurrence since only one of these is active at a time. There's no possibility for a process C to grab the lock as long as A has it (except of course if C decide to mess with the lock file).
How to test
Run the following :
A debug message should say that a lock was added for a given PID (except if the service is already stopped/started)
Validation