infinoted: Wait for upto 5 minutes to kill daemon

Closes #1442.

When disk is very busy, sending KILL signal to the process may not kill it
immediately. So wait upto 5 minutes for it. This does not increase the time in a
regular case if the kill works immediately.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2019-01-28 13:07:15 -08:00 committed by James Valleroy
parent dc9ab52edc
commit c400c21e88
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -25,6 +25,7 @@ import os
import pwd
import shutil
import subprocess
import time
from plinth import action_utils
@ -110,6 +111,19 @@ def parse_arguments():
return parser.parse_args()
def _kill_daemon():
"""Try to kill the infinoted daemon for upto 5 minutes."""
end_time = time.time() + 300
while time.time() < end_time:
try:
subprocess.run(['infinoted', '--kill-daemon'], check=True)
break
except subprocess.CalledProcessError:
pass
time.sleep(1)
def subcommand_setup(_):
"""Configure infinoted after install."""
if not os.path.isfile(CONF_PATH):
@ -155,7 +169,7 @@ def subcommand_setup(_):
'infinoted', '--create-key', '--create-certificate',
'--daemonize'
], check=True)
subprocess.run(['infinoted', '--kill-daemon'], check=True)
_kill_daemon()
finally:
os.umask(old_umask)