Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
27cb51c9
Commit
27cb51c9
authored
Apr 21, 1999
by
Michel Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added hearbeat function to call a ZPublisher.Client method every
configurable number of seconds.
parent
717dadc3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
48 deletions
+92
-48
ZServer/zinit.py
ZServer/zinit.py
+46
-24
lib/python/ZServer/zinit.py
lib/python/ZServer/zinit.py
+46
-24
No files found.
ZServer/zinit.py
View file @
27cb51c9
...
...
@@ -111,6 +111,10 @@ SOFTWARE_HOME = '/projects/users/zs_zope'
START_FILE
=
os
.
path
.
join
(
SOFTWARE_HOME
,
'ZServer'
,
'start.py'
)
pyth
=
sys
.
executable
sys
.
path
.
insert
(
0
,
os
.
path
.
join
(
SOFTWARE_HOME
,
'lib'
,
'python'
))
import
ZPublisher.Client
class
KidDiedOnMeError
:
pass
...
...
@@ -121,13 +125,41 @@ class ForkError:
pass
FORK_ATTEMPTS
=
2
BEAT_DELAY
=
1
VERBOSE
=
1
# If you want the parent to 'pulse' Zope every 'BEAT_DELAY' seconds,
# put the URL to the method you want to call here. This can be any
# methodish object that can be called through the web. Format is:
#
# activities = (("http://x/method", "username", "password"),)
#
# username and password may be None if the method does not require
# authentication.
activities
=
((
'http://localhost:9222/Heart/heart'
,
'michel'
,
'123'
),
)
def
pstamp
(
message
):
print
"zinit: %s: %s"
%
(
time
.
ctime
(
time
.
time
()),
message
)
def
heartbeat
():
print
'tha-thump'
for
a
in
activities
:
try
:
result
=
ZPublisher
.
Client
.
call
(
a
[
0
],
a
[
1
],
a
[
2
])
except
:
pstamp
(
'activity %s failed!'
%
a
[
0
])
return
if
result
and
VERBOSE
:
pstamp
(
'activity %s returned: %s'
%
(
a
[
0
],
result
))
def
forkit
(
attempts
=
FORK_ATTEMPTS
):
while
attempts
:
# if at first you don't succeed...
attempts
=
attempts
+
1
try
:
pid
=
os
.
fork
()
...
...
@@ -149,20 +181,24 @@ def main():
elif
pid
:
# Parent
pstamp
((
'Hi, I just forked off a kid: %s'
%
pid
))
# here we want the pid of the parent
pf
=
open
(
os
.
path
.
join
(
SOFTWARE_HOME
,
'var'
,
'ZServerManager.pid'
),
'w+'
)
pf
.
write
((
"%s"
%
os
.
getpid
()))
pf
.
close
()
p
,
s
=
os
.
waitpid
(
pid
,
0
)
if
s
:
pstamp
((
'Aiieee! %s exited with error code: %s'
%
(
p
,
s
)))
else
:
pstamp
((
'The kid, %s, died on me.'
%
pid
))
raise
KidDiedOnMeError
while
1
:
p
,
s
=
os
.
waitpid
(
pid
,
os
.
WNOHANG
)
if
not
p
:
time
.
sleep
(
BEAT_DELAY
)
heartbeat
()
continue
if
s
:
pstamp
((
'Aiieee! %s exited with error code: %s'
%
(
p
,
s
)))
else
:
pstamp
((
'The kid, %s, died on me.'
%
pid
))
raise
KidDiedOnMeError
else
:
# Child
...
...
@@ -170,29 +206,15 @@ def main():
os
.
execv
(
START_FILE
,
())
except
:
raise
ExecError
os
.
_exit
(
0
)
except
ExecError
:
sys
.
exit
()
except
ForkError
:
sys
.
exit
()
except
KidDiedOnMeError
:
pass
if
__name__
==
'__main__'
:
main
()
lib/python/ZServer/zinit.py
View file @
27cb51c9
...
...
@@ -111,6 +111,10 @@ SOFTWARE_HOME = '/projects/users/zs_zope'
START_FILE
=
os
.
path
.
join
(
SOFTWARE_HOME
,
'ZServer'
,
'start.py'
)
pyth
=
sys
.
executable
sys
.
path
.
insert
(
0
,
os
.
path
.
join
(
SOFTWARE_HOME
,
'lib'
,
'python'
))
import
ZPublisher.Client
class
KidDiedOnMeError
:
pass
...
...
@@ -121,13 +125,41 @@ class ForkError:
pass
FORK_ATTEMPTS
=
2
BEAT_DELAY
=
1
VERBOSE
=
1
# If you want the parent to 'pulse' Zope every 'BEAT_DELAY' seconds,
# put the URL to the method you want to call here. This can be any
# methodish object that can be called through the web. Format is:
#
# activities = (("http://x/method", "username", "password"),)
#
# username and password may be None if the method does not require
# authentication.
activities
=
((
'http://localhost:9222/Heart/heart'
,
'michel'
,
'123'
),
)
def
pstamp
(
message
):
print
"zinit: %s: %s"
%
(
time
.
ctime
(
time
.
time
()),
message
)
def
heartbeat
():
print
'tha-thump'
for
a
in
activities
:
try
:
result
=
ZPublisher
.
Client
.
call
(
a
[
0
],
a
[
1
],
a
[
2
])
except
:
pstamp
(
'activity %s failed!'
%
a
[
0
])
return
if
result
and
VERBOSE
:
pstamp
(
'activity %s returned: %s'
%
(
a
[
0
],
result
))
def
forkit
(
attempts
=
FORK_ATTEMPTS
):
while
attempts
:
# if at first you don't succeed...
attempts
=
attempts
+
1
try
:
pid
=
os
.
fork
()
...
...
@@ -149,20 +181,24 @@ def main():
elif
pid
:
# Parent
pstamp
((
'Hi, I just forked off a kid: %s'
%
pid
))
# here we want the pid of the parent
pf
=
open
(
os
.
path
.
join
(
SOFTWARE_HOME
,
'var'
,
'ZServerManager.pid'
),
'w+'
)
pf
.
write
((
"%s"
%
os
.
getpid
()))
pf
.
close
()
p
,
s
=
os
.
waitpid
(
pid
,
0
)
if
s
:
pstamp
((
'Aiieee! %s exited with error code: %s'
%
(
p
,
s
)))
else
:
pstamp
((
'The kid, %s, died on me.'
%
pid
))
raise
KidDiedOnMeError
while
1
:
p
,
s
=
os
.
waitpid
(
pid
,
os
.
WNOHANG
)
if
not
p
:
time
.
sleep
(
BEAT_DELAY
)
heartbeat
()
continue
if
s
:
pstamp
((
'Aiieee! %s exited with error code: %s'
%
(
p
,
s
)))
else
:
pstamp
((
'The kid, %s, died on me.'
%
pid
))
raise
KidDiedOnMeError
else
:
# Child
...
...
@@ -170,29 +206,15 @@ def main():
os
.
execv
(
START_FILE
,
())
except
:
raise
ExecError
os
.
_exit
(
0
)
except
ExecError
:
sys
.
exit
()
except
ForkError
:
sys
.
exit
()
except
KidDiedOnMeError
:
pass
if
__name__
==
'__main__'
:
main
()
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