[monit/services] python plus lisible

darcs-hash:20090817092329-bd074-0128bb6a3cd830e7eda4c097943966b251bf7b13.gz
This commit is contained in:
Antoine Durand-Gasselin 2009-08-17 11:23:29 +02:00
parent 18d5724975
commit 0277cb5da4

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8; mode: python -*-
import sre
import re
include("ip")
@ -10,26 +10,28 @@ info["perms"] = 0644
header()
import sys
def service(group,
name=None,
init=None,
pidf=None,
pidp=None,
extra=[],
max_restart=5):
def service(group, **kw):
"""Permet de définir un service monit.
Les arguments supplémentaires peuvent être:
name (par défault le nom du groupe)
init (le nom du script de démarrage dans /etc/init.d, (par défaut name))
pidp (le nom du fichier de pid (par défaut /var/run/<pidf>.pid))
extra (des lignes supplémentaires)"""
if group == None or has(group):
name = name or group
init = init or name
pidf = pidf or name
pidp = pidp or "/var/run/%s.pid" % pidf
name = kw.get('name', group)
init = kw.get('init', name)
pidp = kw.get('pidp', "/var/run/%s.pid" % kw.get('pidf', name))
start_cmd = kw.get('start_cmd', '/etc/init.d/%s start' % init)
stop_cmd = kw.get('stop_cmd', '/etc/init.d/%s stop' % init)
print ('''# %(name)s
check process %(name)s with pidfile %(pidp)s
start program = "/etc/init.d/%(init)s start"
stop program = "/etc/init.d/%(init)s stop"''' %
{ "name": name,
"pidp": pidp,
"init": init })
for line in extra:
start program = "%(start_cmd)"
stop program = "%(stop_cmd)"''' % locals())
max_restart = kw.get('max_restart', 5)
for line in kw.get('extra', []):
if line:
print " ", line
print " if %d restarts within 5 cycles then timeout" % max_restart
@ -202,7 +204,7 @@ for line in metadata.Probes["fstab_local"].splitlines():
continue
# on découpe la ligne
[fs, mntpoint, type, options, dump, pass_] = sre.split('[ \t]*',line)
[fs, mntpoint, type, options, dump, pass_] = re.split('[ \t]*',line)
options = options.split(",")
# on saute si c'est une partition non montée au démarrage