Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ophélie Gagnard
slapos
Commits
c898d62c
Commit
c898d62c
authored
Jun 11, 2014
by
Tristan Cavelier
Committed by
Cédric Le Ninivin
Jun 13, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
monitor: timeout added for monitor subprocesses
parent
8c887705
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
9 deletions
+32
-9
stack/monitor/buildout.cfg
stack/monitor/buildout.cfg
+1
-1
stack/monitor/monitor.py.in
stack/monitor/monitor.py.in
+31
-8
No files found.
stack/monitor/buildout.cfg
View file @
c898d62c
...
@@ -49,7 +49,7 @@ mode = 0644
...
@@ -49,7 +49,7 @@ mode = 0644
recipe = hexagonit.recipe.download
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/${:filename}
url = ${:_profile_base_location_}/${:filename}
download-only = true
download-only = true
md5sum =
1e7b4698f6627150b1eb783b06f8b13a
md5sum =
cb2f15850d3dc82459a0044adb4416cf
destination = ${buildout:directory}/parts/monitor-template-monitor-bin
destination = ${buildout:directory}/parts/monitor-template-monitor-bin
filename = monitor.py.in
filename = monitor.py.in
mode = 0644
mode = 0644
...
...
stack/monitor/monitor.py.in
View file @
c898d62c
...
@@ -7,6 +7,7 @@ import subprocess
...
@@ -7,6 +7,7 @@ import subprocess
import sys
import sys
import sqlite3
import sqlite3
import time
import time
import threading
from optparse import OptionParser, make_option
from optparse import OptionParser, make_option
...
@@ -34,6 +35,26 @@ option_list = [
...
@@ -34,6 +35,26 @@ option_list = [
help="add the file containing services\'pid to the files to monitor")
help="add the file containing services\'pid to the files to monitor")
]
]
class Popen(subprocess.Popen):
__timeout = None
def timeout(self, delay, delay_before_kill=5):
if self.__timeout is not None: self.__timeout.cancel()
self.__timeout = threading.Timer(delay, self.stop, [delay_before_kill])
self.__timeout.start()
def waiter():
self.wait()
self.__timeout.cancel()
threading.Thread(target=waiter).start()
def stop(self, delay_before_kill=5):
if self.__timeout is not None: self.__timeout.cancel()
self.terminate()
t = threading.Timer(delay_before_kill, self.kill)
t.start()
r = self.wait()
t.cancel()
return r
def init_db():
def init_db():
db = sqlite3.connect(db_path)
db = sqlite3.connect(db_path)
...
@@ -89,14 +110,15 @@ def runServices(directory):
...
@@ -89,14 +110,15 @@ def runServices(directory):
def runScripts(directory):
def runScripts(directory):
scripts = getListOfScripts(directory)
scripts = getListOfScripts(directory)
script_timeout = 3
# XXX script_timeout could be passed as parameters
script_timeout = 60 # in seconds
result = {}
result = {}
for script in scripts:
for script in scripts:
command = [os.path.join(promise_dir, script)]
command = [os.path.join(promise_dir, script)]
script = os.path.basename(command[0])
script = os.path.basename(command[0])
result[script] = ''
result[script] = ''
process_handler =
subprocess.
Popen(command,
process_handler = Popen(command,
cwd=instance_path,
cwd=instance_path,
env=None if sys.platform == 'cygwin' else {},
env=None if sys.platform == 'cygwin' else {},
stdout=subprocess.PIPE,
stdout=subprocess.PIPE,
...
@@ -106,7 +128,8 @@ def runScripts(directory):
...
@@ -106,7 +128,8 @@ def runScripts(directory):
process_handler.stdin.close()
process_handler.stdin.close()
process_handler.stdin = None
process_handler.stdin = None
time.sleep(script_timeout)
process_handler.timeout(script_timeout)
process_handler.wait()
if process_handler.poll() is None:
if process_handler.poll() is None:
process_handler.terminate()
process_handler.terminate()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment