Skip to content

Commit e91019f

Browse files
authored
Merge pull request #1140 from jc21/adds-logrotation
Adds logrotation
2 parents 8a37ec7 + 673f40b commit e91019f

File tree

12 files changed

+76
-18
lines changed

12 files changed

+76
-18
lines changed

backend/setup.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,29 @@ const setupCertbotPlugins = () => {
201201
});
202202
};
203203

204+
205+
/**
206+
* Starts a timer to call run the logrotation binary every two days
207+
* @returns {Promise}
208+
*/
209+
const setupLogrotation = () => {
210+
const intervalTimeout = 1000 * 60 * 60 * 24 * 2; // 2 days
211+
212+
const runLogrotate = async () => {
213+
await utils.exec('logrotate /etc/logrotate.d/nginx-proxy-manager');
214+
logger.info('Logrotate completed.');
215+
};
216+
217+
logger.info('Logrotate Timer initialized');
218+
setInterval(runLogrotate, intervalTimeout);
219+
// And do this now as well
220+
return runLogrotate();
221+
};
222+
204223
module.exports = function () {
205224
return setupJwt()
206225
.then(setupDefaultUser)
207226
.then(setupDefaultSettings)
208-
.then(setupCertbotPlugins);
227+
.then(setupCertbotPlugins)
228+
.then(setupLogrotation);
209229
};

backend/templates/dead_host.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ server {
77
{% include "_hsts.conf" %}
88
{% include "_forced_ssl.conf" %}
99

10-
access_log /data/logs/dead_host-{{ id }}.log standard;
10+
access_log /data/logs/dead-host-{{ id }}_access.log standard;
11+
error_log /data/logs/dead-host-{{ id }}_error.log warn;
1112

1213
{{ advanced_config }}
1314

backend/templates/default.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ server {
1212
#listen [::]:80;
1313
{% endif %}
1414
server_name default-host.localhost;
15-
access_log /data/logs/default_host.log combined;
15+
access_log /data/logs/default-host_access.log combined;
16+
error_log /data/logs/default-host_error.log warn;
1617
{% include "_exploits.conf" %}
1718

1819
{%- if value == "404" %}

backend/templates/letsencrypt-request.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ server {
88

99
server_name {{ domain_names | join: " " }};
1010

11-
access_log /data/logs/letsencrypt-requests.log standard;
11+
access_log /data/logs/letsencrypt-requests_access.log standard;
12+
error_log /data/logs/letsencrypt-requests_error.log warn;
1213

1314
include conf.d/include/letsencrypt-acme-challenge.conf;
1415

backend/templates/proxy_host.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ proxy_set_header Connection $http_connection;
1919
proxy_http_version 1.1;
2020
{% endif %}
2121

22-
23-
access_log /data/logs/proxy_host-{{ id }}.log proxy;
22+
access_log /data/logs/proxy-host-{{ id }}_access.log proxy;
23+
error_log /data/logs/proxy-host-{{ id }}_error.log warn;
2424

2525
{{ advanced_config }}
2626

backend/templates/redirection_host.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ server {
99
{% include "_hsts.conf" %}
1010
{% include "_forced_ssl.conf" %}
1111

12-
access_log /data/logs/redirection_host-{{ id }}.log standard;
12+
access_log /data/logs/redirection-host-{{ id }}_access.log standard;
13+
error_log /data/logs/redirection-host-{{ id }}_error.log warn;
1314

1415
{{ advanced_config }}
1516

docker/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ENV SUPPRESS_NO_CONFIG_WARNING=1 \
2020

2121
RUN echo "fs.file-max = 65535" > /etc/sysctl.conf \
2222
&& apt-get update \
23-
&& apt-get install -y --no-install-recommends jq \
23+
&& apt-get install -y --no-install-recommends jq logrotate \
2424
&& apt-get clean \
2525
&& rm -rf /var/lib/apt/lists/*
2626

@@ -43,6 +43,9 @@ COPY docker/rootfs /
4343
# Remove frontend service not required for prod, dev nginx config as well
4444
RUN rm -rf /etc/services.d/frontend /etc/nginx/conf.d/dev.conf
4545

46+
# Change permission of logrotate config file
47+
RUN chmod 644 /etc/logrotate.d/nginx-proxy-manager
48+
4649
VOLUME [ "/data", "/etc/letsencrypt" ]
4750
ENTRYPOINT [ "/init" ]
4851
HEALTHCHECK --interval=5s --timeout=3s CMD /bin/check-health

docker/dev/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ENV S6_LOGGING=0 \
77

88
RUN echo "fs.file-max = 65535" > /etc/sysctl.conf \
99
&& apt-get update \
10-
&& apt-get install -y certbot jq python3-pip \
10+
&& apt-get install -y certbot jq python3-pip logrotate \
1111
&& apt-get clean \
1212
&& rm -rf /var/lib/apt/lists/*
1313

@@ -18,6 +18,7 @@ RUN cd /usr \
1818

1919
COPY rootfs /
2020
RUN rm -f /etc/nginx/conf.d/production.conf
21+
RUN chmod 644 /etc/logrotate.d/nginx-proxy-manager
2122

2223
# s6 overlay
2324
RUN curl -L -o /tmp/s6-overlay-amd64.tar.gz "https://github.com/just-containers/s6-overlay/releases/download/v1.22.1.0/s6-overlay-amd64.tar.gz" \

docker/docker-compose.dev.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# WARNING: This is a DEVELOPMENT docker-compose file, it should not be used for production.
2-
version: "3"
2+
version: "3.5"
33
services:
4-
54
npm:
65
image: nginxproxymanager:dev
6+
container_name: npm_core
77
build:
88
context: ./
99
dockerfile: ./dev/Dockerfile
@@ -36,6 +36,7 @@ services:
3636

3737
db:
3838
image: jc21/mariadb-aria
39+
container_name: npm_db
3940
networks:
4041
- nginx_proxy_manager
4142
environment:
@@ -47,21 +48,26 @@ services:
4748
- db_data:/var/lib/mysql
4849

4950
swagger:
50-
image: 'swaggerapi/swagger-ui:latest'
51+
image: "swaggerapi/swagger-ui:latest"
52+
container_name: npm_swagger
5153
ports:
5254
- 3001:80
5355
networks:
5456
- nginx_proxy_manager
5557
environment:
5658
URL: "http://127.0.0.1:3081/api/schema"
57-
PORT: '80'
59+
PORT: "80"
5860
depends_on:
5961
- npm
6062

6163
volumes:
6264
npm_data:
65+
name: npm_core_data
6366
le_data:
67+
name: npm_le_data
6468
db_data:
69+
name: npm_db_data
6570

6671
networks:
6772
nginx_proxy_manager:
73+
name: npm_network
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/data/logs/*_access.log /data/logs/*/access.log {
2+
create 0644 root root
3+
weekly
4+
rotate 4
5+
missingok
6+
notifempty
7+
compress
8+
sharedscripts
9+
postrotate
10+
/bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
11+
endscript
12+
}
13+
14+
/data/logs/*_error.log /data/logs/*/error.log {
15+
create 0644 root root
16+
weekly
17+
rotate 10
18+
missingok
19+
notifempty
20+
compress
21+
sharedscripts
22+
postrotate
23+
/bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
24+
endscript
25+
}

0 commit comments

Comments
 (0)