Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
nexedi
re6stnet
Commits
34e018ef
Commit
34e018ef
authored
May 07, 2013
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
42495e18
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
16 deletions
+30
-16
re6stnet
re6stnet
+30
-16
No files found.
re6stnet
View file @
34e018ef
...
@@ -117,6 +117,31 @@ def getConfig():
...
@@ -117,6 +117,31 @@ def getConfig():
def
renew
(
*
args
):
def
renew
(
*
args
):
raise
ReexecException
(
"Restart to renew certificate"
)
raise
ReexecException
(
"Restart to renew certificate"
)
def
maybe_renew
(
path
,
cert
,
info
,
renew
):
while
True
:
next_renew
=
utils
.
notAfter
(
cert
)
-
RENEW_PERIOD
if
time
.
time
()
<
next_renew
:
return
cert
,
next_renew
try
:
pem
=
renew
()
if
not
pem
or
pem
==
crypto
.
dump_certificate
(
crypto
.
FILETYPE_PEM
,
cert
):
exc_info
=
0
break
cert
=
crypto
.
load_certificate
(
crypto
.
FILETYPE_PEM
,
pem
)
except
Exception
:
exc_info
=
1
break
new_path
=
path
+
'.new'
with
open
(
new_path
,
'w'
)
as
f
:
f
.
write
(
pem
)
os
.
rename
(
new_path
,
path
)
logging
.
info
(
"%s renewed until %s"
,
info
,
time
.
ctime
(
utils
.
notAfter
(
cert
)))
logging
.
error
(
"%s not renewed. Will retry tomorrow."
,
info
,
exc_info
=
exc_info
)
return
cert
,
time
.
time
()
+
86400
def
main
():
def
main
():
# Get arguments
# Get arguments
config
=
getConfig
()
config
=
getConfig
()
...
@@ -149,22 +174,11 @@ def main():
...
@@ -149,22 +174,11 @@ def main():
signal
.
signal
(
signal
.
SIGTERM
,
lambda
*
args
:
sys
.
exit
())
signal
.
signal
(
signal
.
SIGTERM
,
lambda
*
args
:
sys
.
exit
())
registry
=
RegistryClient
(
config
.
registry
,
config
.
key
,
ca
)
registry
=
RegistryClient
(
config
.
registry
,
config
.
key
,
ca
)
while
True
:
cert
,
next_renew
=
maybe_renew
(
config
.
cert
,
cert
,
"Certificate"
,
next_renew
=
utils
.
notAfter
(
cert
)
-
RENEW_PERIOD
lambda
:
registry
.
renewCertificate
(
prefix
))
if
time
.
time
()
<
next_renew
:
ca
,
ca_renew
=
maybe_renew
(
config
.
ca
,
ca
,
"CA Certificate"
,
registry
.
getCa
)
break
if
next_renew
>
ca_renew
:
pem
=
registry
.
renewCertificate
(
prefix
)
next_renew
=
ca_renew
if
not
pem
or
pem
==
crypto
.
dump_certificate
(
crypto
.
FILETYPE_PEM
,
cert
):
logging
.
warning
(
"Certificate not renewed. Will retry tomorrow."
)
next_renew
=
time
.
time
()
+
86400
break
cert
=
crypto
.
load_certificate
(
crypto
.
FILETYPE_PEM
,
pem
)
path
=
config
.
cert
+
'.new'
with
open
(
path
,
'w'
)
as
f
:
f
.
write
(
pem
)
os
.
rename
(
path
,
config
.
cert
)
logging
.
info
(
"Certificate renewed until %s"
,
time
.
ctime
(
utils
.
notAfter
(
cert
)))
if
config
.
max_clients
is
None
:
if
config
.
max_clients
is
None
:
config
.
max_clients
=
config
.
client_count
*
2
config
.
max_clients
=
config
.
client_count
*
2
...
...
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