2 #Copyright (C) 2009-2011 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
5 # Gregory Starck, g.starck@gmail.com
6 # Hartmut Goebel, h.goebel@goebel-consult.de
8 #This file is part of Shinken.
10 #Shinken is free software: you can redistribute it and/or modify
11 #it under the terms of the GNU Affero General Public License as published by
12 #the Free Software Foundation, either version 3 of the License, or
13 #(at your option) any later version.
15 #Shinken is distributed in the hope that it will be useful,
16 #but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 #GNU Affero General Public License for more details.
20 #You should have received a copy of the GNU Affero General Public License
21 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
24 #For the Shinken application, I try to respect
25 #The Zen of Python, by Tim Peters. It's just some
26 #very goods ideas that make Python programming very fun
27 #and efficient. If it's good for Python, it must be good for
32 #Beautiful is better than ugly.
33 #Explicit is better than implicit.
34 #Simple is better than complex.
35 #Complex is better than complicated.
36 #Flat is better than nested.
37 #Sparse is better than dense.
39 #Special cases aren't special enough to break the rules.
40 #Although practicality beats purity.
41 #Errors should never pass silently.
42 #Unless explicitly silenced.
43 #In the face of ambiguity, refuse the temptation to guess.
44 #There should be one-- and preferably only one --obvious way to do it.
45 #Although that way may not be obvious at first unless you're Dutch.
46 #Now is better than never.
47 #Although never is often better than *right* now.
48 #If the implementation is hard to explain, it's a bad idea.
49 #If the implementation is easy to explain, it may be a good idea.
50 #Namespaces are one honking great idea -- let's do more of those!
53 #This class is the application in charge of the scheduling
54 #The scheduler listens to the Arbiter for the configuration sent through
55 #the port given as first argument.
56 #The configuration sent by the arbiter specifies which checks and actions
57 #the scheduler must schedule, and a list of reactionners and pollers
59 #When the reactionner is already launched and has its own conf, it still
60 #listens to arbiter (one a timeout)
61 #In case the arbiter has a new conf to send, the reactionner is stopped
62 #and a new one is created.
68 # We try to raise up recusion limit on
69 # but we don't have resource module on windows
72 # All the pickle will ask for a lot of recursion, so we must make
73 # sure to set it at a high value. The maximum recursion depth depends
74 # on the Python version and the process limit "stack size".
75 # The factors used were acquired by testing a broad range of installations
76 stacksize_soft
, stacksize_hard
= resource
.getrlimit(3)
77 if sys
.version_info
< (2,6):
78 sys
.setrecursionlimit(int(stacksize_soft
* 0.65 + 1100))
79 elif sys
.version_info
< (3,):
80 sys
.setrecursionlimit(int(stacksize_soft
* 1.9 + 3200))
82 sys
.setrecursionlimit(int(stacksize_soft
* 2.4 + 3200))
87 # If importing shinken fails, try to load from current directory
88 # or parent directory to support running without installation.
89 # Submodules will then be loaded from there, too.
91 if not hasattr(os
, "getuid") or os
.getuid() != 0:
92 imp
.load_module('shinken', *imp
.find_module('shinken', [".", ".."]))
94 from shinken
.daemons
.schedulerdaemon
import Shinken
95 from shinken
.bin
import VERSION
98 parser
= optparse
.OptionParser(
99 "%prog [options]", version
="%prog " + VERSION
)
100 parser
.add_option('-c', '--config',
101 dest
="config_file", metavar
="CONFIG-FILE",
103 parser
.add_option('-d', '--daemon', action
='store_true',
105 help="Run in daemon mode")
106 parser
.add_option('-r', '--replace', action
='store_true',
108 help="Replace previous running scheduler")
109 parser
.add_option('--debugfile', dest
='debug_file',
110 help=("Debug file. Default: not used "
111 "(why debug a bug free program? :) )"))
112 opts
, args
= parser
.parse_args()
114 parser
.error("Does not accept any argument.")
116 daemon
= Shinken(debug
=opts
.debug_file
is not None, **opts
.__dict
__)