[monit/services] python plus lisible
darcs-hash:20090817092329-bd074-0128bb6a3cd830e7eda4c097943966b251bf7b13.gz
This commit is contained in:
parent
18d5724975
commit
0277cb5da4
1 changed files with 22 additions and 20 deletions
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8; mode: python -*-
|
# -*- coding: utf-8; mode: python -*-
|
||||||
|
|
||||||
import sre
|
import re
|
||||||
|
|
||||||
include("ip")
|
include("ip")
|
||||||
|
|
||||||
|
@ -10,26 +10,28 @@ info["perms"] = 0644
|
||||||
|
|
||||||
header()
|
header()
|
||||||
import sys
|
import sys
|
||||||
def service(group,
|
def service(group, **kw):
|
||||||
name=None,
|
"""Permet de définir un service monit.
|
||||||
init=None,
|
|
||||||
pidf=None,
|
Les arguments supplémentaires peuvent être:
|
||||||
pidp=None,
|
name (par défault le nom du groupe)
|
||||||
extra=[],
|
init (le nom du script de démarrage dans /etc/init.d, (par défaut name))
|
||||||
max_restart=5):
|
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):
|
if group == None or has(group):
|
||||||
name = name or group
|
name = kw.get('name', group)
|
||||||
init = init or name
|
init = kw.get('init', name)
|
||||||
pidf = pidf or name
|
pidp = kw.get('pidp', "/var/run/%s.pid" % kw.get('pidf', name))
|
||||||
pidp = pidp or "/var/run/%s.pid" % pidf
|
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
|
print ('''# %(name)s
|
||||||
check process %(name)s with pidfile %(pidp)s
|
check process %(name)s with pidfile %(pidp)s
|
||||||
start program = "/etc/init.d/%(init)s start"
|
start program = "%(start_cmd)"
|
||||||
stop program = "/etc/init.d/%(init)s stop"''' %
|
stop program = "%(stop_cmd)"''' % locals())
|
||||||
{ "name": name,
|
|
||||||
"pidp": pidp,
|
max_restart = kw.get('max_restart', 5)
|
||||||
"init": init })
|
for line in kw.get('extra', []):
|
||||||
for line in extra:
|
|
||||||
if line:
|
if line:
|
||||||
print " ", line
|
print " ", line
|
||||||
print " if %d restarts within 5 cycles then timeout" % max_restart
|
print " if %d restarts within 5 cycles then timeout" % max_restart
|
||||||
|
@ -182,7 +184,7 @@ for i in range(0,dernierecarte):
|
||||||
name = "mumudvb%d" % i,
|
name = "mumudvb%d" % i,
|
||||||
init = "mumudvb",
|
init = "mumudvb",
|
||||||
pidf = "mumudvb/mumudvb_carte%d" % i)
|
pidf = "mumudvb/mumudvb_carte%d" % i)
|
||||||
|
|
||||||
@check file file/var/log/syslog with path /var/log/syslog
|
@check file file/var/log/syslog with path /var/log/syslog
|
||||||
@ if timestamp > 15 minutes then alert
|
@ if timestamp > 15 minutes then alert
|
||||||
@
|
@
|
||||||
|
@ -202,7 +204,7 @@ for line in metadata.Probes["fstab_local"].splitlines():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# on découpe la ligne
|
# 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(",")
|
options = options.split(",")
|
||||||
|
|
||||||
# on saute si c'est une partition non montée au démarrage
|
# on saute si c'est une partition non montée au démarrage
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue