1 # Copyright (C) 2008-2010, Eduardo Silva <edsiper@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 from child
import Child
23 from listener
import Listener
24 from config
import PalmConfig
33 # Read Palm configuration
34 self
.conf
= PalmConfig()
35 self
.conf
.readconf("conf/palm.conf")
37 signal
.signal(signal
.SIGINT
, self
._on
_sigint
_cb
)
43 def _on_sigint_cb(self
, frame
, a
):
45 os
.kill(self
._palms
[p
], signal
.SIGKILL
)
50 print "Monkey Palm Server", VERSION
51 print "Visit us: http://www.monkey-project.com"
53 def create_palms(self
):
54 for h
in self
.conf
.get_handlers():
55 # Handler configuration
57 port
= int(self
.conf
.get(h
, 'Port'))
59 self
.conf_error(h
, 'Port')
62 childs
= int(self
.conf
.get(h
, 'Childs'))
64 self
.conf_error(h
, 'Childs')
67 bin
= self
.conf
.get(h
, 'Exec')
72 opts
= self
.conf
.get(h
, 'Arguments')
77 debug("[+] Handler [%s] running on port %i, %i childs" % (h
, port
, childs
))
79 # Creating Palm under process context
84 p
= Palm(h
, port
, bin
, opts
)
85 p
.create_n_childs(childs
)
92 def conf_error(self
, h
, var
):
93 print "\nPalm config error, no option '%s' in handler '%s'" % (var
, h
)
99 def __init__(self
, name
, port
, bin
, opts
):
105 self
.listen
= Listener(port
)
106 self
.s
= self
.listen
.s
108 def create_n_childs(self
, n
):
112 def create_child(self
):
113 child
= Child(self
.name
, self
.s
, self
)
114 self
._register
_child
(child
)
116 def _register_child(self
, child
):
117 self
._childs
.append(child
)
119 def get_child_list(self
):
122 def get_childs_len(self
):
123 return len(self
._childs
)
125 def kill_childs(self
):
126 for c
in self
._childs
: