Commit 65257733 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

runner: introduce function to test running process from pidfile

parent 28321c70
...@@ -104,3 +104,18 @@ def setHandler(sig_list=None): ...@@ -104,3 +104,18 @@ def setHandler(sig_list=None):
sig_list = [signal.SIGTERM] sig_list = [signal.SIGTERM]
for sig in sig_list: for sig in sig_list:
signal.signal(sig, handler) signal.signal(sig, handler)
def isPidFileProcessRunning(pidfile):
"""
Test if the pidfile exist and if the process is still active
"""
if os.path.exists(pidfile):
try:
pid = int(open(pidfile, 'r').readline())
except ValueError:
pid = None
# XXX This could use psutil library.
if pid and os.path.exists("/proc/%s" % pid):
return True
return False
...@@ -20,7 +20,7 @@ from flask import jsonify ...@@ -20,7 +20,7 @@ from flask import jsonify
from slapos.runner.gittools import cloneRepo from slapos.runner.gittools import cloneRepo
from slapos.runner.process import Popen, isRunning, killRunningProcess from slapos.runner.process import Popen, isRunning, killRunningProcess, isPidFileProcessRunning
from slapos.htpasswd import HtpasswdFile from slapos.htpasswd import HtpasswdFile
import slapos.slap import slapos.slap
...@@ -278,6 +278,8 @@ def runSoftwareWithLock(config, lock=True): ...@@ -278,6 +278,8 @@ def runSoftwareWithLock(config, lock=True):
return False return False
slapgrid_pid = os.path.join(config['run_dir'], 'slapgrid-sr.pid') slapgrid_pid = os.path.join(config['run_dir'], 'slapgrid-sr.pid')
if isPidFileProcessRunning(slapgrid_pid):
return False
if not os.path.exists(config['software_root']): if not os.path.exists(config['software_root']):
os.mkdir(config['software_root']) os.mkdir(config['software_root'])
stopProxy(config) stopProxy(config)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment