Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
105
Merge Requests
105
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos
Commits
24865c22
Commit
24865c22
authored
Nov 14, 2021
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
software/nginx-push-stream: implement log rotation
parent
690bafbf
Pipeline
#18420
passed with stage
Changes
4
Pipelines
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
4 deletions
+73
-4
software/nginx-push-stream/buildout.hash.cfg
software/nginx-push-stream/buildout.hash.cfg
+2
-2
software/nginx-push-stream/instance.cfg.in
software/nginx-push-stream/instance.cfg.in
+13
-0
software/nginx-push-stream/template-nginx.cfg.in
software/nginx-push-stream/template-nginx.cfg.in
+1
-1
software/nginx-push-stream/test/test.py
software/nginx-push-stream/test/test.py
+57
-1
No files found.
software/nginx-push-stream/buildout.hash.cfg
View file @
24865c22
[template]
filename = instance.cfg.in
md5sum =
56e986c74ef236f261834c57f5861ce0
md5sum =
87fd83d33ba786550a45f484b3ae2b24
[template-nginx-configuration]
filename = template-nginx.cfg.in
md5sum =
022e4b53e1b2db16c4e518fe76f638fa
md5sum =
3eb7dda365d30c3c3c2ce939bbc607d4
software/nginx-push-stream/instance.cfg.in
View file @
24865c22
[buildout]
parts =
nginx-service
cron-service
cron-entry-logrotate
logrotate-entry-nginx
promises
publish-connection-information
extends = ${monitor-template:rendered}
...
...
@@ -46,6 +49,7 @@ output = $${directory:etc}/nginx.cfg
mode = 0600
access-log = $${directory:log}/nginx-access.log
error-log = $${directory:log}/nginx-error.log
pid-file = $${directory:run}/nginx.pid
ip = $${slap-configuration:ipv6-random}
local-ip = $${slap-configuration:ipv4-random}
port = 9443
...
...
@@ -68,6 +72,15 @@ cert-file = $${directory:ssl}/${:_buildout_section_name_}.cert
common-name = $${nginx-configuration:ip}
stop-on-error = true
[logrotate-entry-nginx]
<= logrotate-entry-base
name = nginx
log =
$${nginx-configuration:access-log}
$${nginx-configuration:error-log}
post =
test ! -s $${nginx-configuration:pid-file} || kill -USR1 $(cat "$${nginx-configuration:pid-file}")
[promises]
recipe =
promises =
...
...
software/nginx-push-stream/template-nginx.cfg.in
View file @
24865c22
daemon off; # run in the foreground so supervisord can look after it
worker_processes 4;
pid $${
directory:run}/nginx.pid
;
pid $${
nginx-configuration:pid-file}
;
events {
worker_connections 768;
...
...
software/nginx-push-stream/test/test.py
View file @
24865c22
...
...
@@ -25,12 +25,16 @@
#
##############################################################################
import
functools
import
os
import
lzma
import
multiprocessing
import
urllib.parse
import
uritemplate
import
requests
from
slapos.testing.utils
import
CrontabMixin
from
slapos.testing.testcase
import
makeModuleSetUpAndTestCaseClass
setUpModule
,
SlapOSInstanceTestCase
=
makeModuleSetUpAndTestCaseClass
(
...
...
@@ -38,7 +42,7 @@ setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'..'
,
'software.cfg'
)))
class
TestNginxPushStream
(
SlapOSInstanceTestCase
):
class
TestNginxPushStream
(
SlapOSInstanceTestCase
,
CrontabMixin
):
def
setUp
(
self
):
self
.
connection_parameters
=
\
self
.
computer_partition
.
getConnectionParameterDict
()
...
...
@@ -83,3 +87,55 @@ class TestNginxPushStream(SlapOSInstanceTestCase):
self
.
assertEqual
(
q
.
get_nowait
(),
b': '
)
self
.
assertEqual
(
q
.
get_nowait
(),
b'data: Hello'
)
def
test_log_rotation
(
self
):
status_url
=
urllib
.
parse
.
urljoin
(
self
.
connection_parameters
[
'publisher-url'
],
'/status'
)
error_url
=
urllib
.
parse
.
urljoin
(
self
.
connection_parameters
[
'publisher-url'
],
'/..'
)
log_file_path
=
functools
.
partial
(
os
.
path
.
join
,
self
.
computer_partition_root_path
,
'var'
,
'log'
,
)
rotated_file_path
=
functools
.
partial
(
os
.
path
.
join
,
self
.
computer_partition_root_path
,
'srv'
,
'backup'
,
'logrotate'
,
)
requests
.
get
(
status_url
,
verify
=
False
)
with
open
(
log_file_path
(
'nginx-access.log'
))
as
f
:
self
.
assertIn
(
'GET /status HTTP'
,
f
.
read
())
requests
.
get
(
error_url
,
verify
=
False
)
with
open
(
log_file_path
(
'nginx-error.log'
))
as
f
:
self
.
assertIn
(
'forbidden'
,
f
.
read
())
# first log rotation initialize the state, but does not actually rotate
self
.
_executeCrontabAtDate
(
'logrotate'
,
'2050-01-01'
)
self
.
_executeCrontabAtDate
(
'logrotate'
,
'2050-01-02'
)
# today's file is not compressed
with
open
(
rotated_file_path
(
'nginx-access.log-20500102'
))
as
f
:
self
.
assertIn
(
'GET /status HTTP'
,
f
.
read
())
with
open
(
rotated_file_path
(
'nginx-error.log-20500102'
))
as
f
:
self
.
assertIn
(
'forbidden'
,
f
.
read
())
# after rotation, the program re-opened original log file and writes in
# expected location.
requests
.
get
(
status_url
,
verify
=
False
)
with
open
(
log_file_path
(
'nginx-access.log'
))
as
f
:
self
.
assertIn
(
'GET /status HTTP'
,
f
.
read
())
requests
.
get
(
error_url
,
verify
=
False
)
with
open
(
log_file_path
(
'nginx-error.log'
))
as
f
:
self
.
assertIn
(
'forbidden'
,
f
.
read
())
self
.
_executeCrontabAtDate
(
'logrotate'
,
'2050-01-03'
)
# yesterday's file are compressed
with
lzma
.
open
(
rotated_file_path
(
'nginx-access.log-20500102.xz'
),
'rt'
)
as
f
:
self
.
assertIn
(
'GET /status HTTP'
,
f
.
read
())
with
lzma
.
open
(
rotated_file_path
(
'nginx-error.log-20500102.xz'
),
'rt'
)
as
f
:
self
.
assertIn
(
'forbidden'
,
f
.
read
())
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