ghost icon indicating copy to clipboard operation
ghost copied to clipboard

Log rotation

Open thedotedge opened this issue 3 years ago • 4 comments

Hi, It would be great to have logrotate preconfigured, since /var/lib/ghost/content/logs folder is ever-growing. That cause issues when deploying to k8s, since pod would eventually crash:

[ghost-56f4c644f9-gps8f ghost]  [2021-11-24 15:46:52] [36mINFO[39m Ghost server started in 0.512s
[ghost-56f4c644f9-gps8f ghost]  events.js:377
[ghost-56f4c644f9-gps8f ghost]        throw er; // Unhandled 'error' event
[ghost-56f4c644f9-gps8f ghost]        ^
[ghost-56f4c644f9-gps8f ghost]  
[ghost-56f4c644f9-gps8f ghost]  Error: ENOSPC: no space left on device, write
[ghost-56f4c644f9-gps8f ghost]  Emitted 'error' event on Logger instance at:
[ghost-56f4c644f9-gps8f ghost]      at WriteStream.onStreamError (/var/lib/ghost/versions/4.20.3/node_modules/bunyan/lib/bunyan.js:627:18)
[ghost-56f4c644f9-gps8f ghost]      at WriteStream.emit (events.js:400:28)
[ghost-56f4c644f9-gps8f ghost]      at emitErrorNT (internal/streams/destroy.js:106:8)
[ghost-56f4c644f9-gps8f ghost]      at emitErrorCloseNT (internal/streams/destroy.js:74:3)
[ghost-56f4c644f9-gps8f ghost]      at processTicksAndRejections (internal/process/task_queues.js:82:21) {
[ghost-56f4c644f9-gps8f ghost]    errno: -28,
[ghost-56f4c644f9-gps8f ghost]    code: 'ENOSPC',
[ghost-56f4c644f9-gps8f ghost]    syscall: 'write'
[ghost-56f4c644f9-gps8f ghost]  }

thedotedge avatar Nov 24 '21 17:11 thedotedge

I'm a bit confused -- from what I read in https://ghost.org/docs/config/#logging, log rotation should be already enabled by default? Did you customize the logging configuration?

tianon avatar Nov 24 '21 21:11 tianon

That's the thing — I have not, so it should work. However, the actual outcome was a single file of 3.4G that has eaten up volume space.

By default Ghost keeps 10 log files and rotates every day. Rotation is enabled by default in production and disabled in development.

contrary to the default mentioned in the linked documentation, this image defaults to NODE_ENV=production (so development mode needs to be explicitly specified if desired)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ghost
  labels:
    app: ghost
    k10/injectKanisterSidecar: "true"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ghost
      tier: web
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: ghost
        tier: web
    spec:
      containers:
        - name: ghost
          # https://github.com/TryGhost/Ghost/releases
          # https://hub.docker.com/_/ghost
          image: ghost:4.20.3
          ports:
            - containerPort: 2368
          env: 
            - name: url
              value: https://site.com/blog/
            - name: database__client
              value: mysql
            - name: database__connection__host
              value: ghost-mariadb
            - name: database__connection__user
              value: root
            - name: database__connection__password
              valueFrom:
                secretKeyRef:
                  name: ghost-mariadb
                  key: root-password
            - name: database__connection__database
              value: ghost
            - name: mail__transport
              value: "SMTP"
            - name: mail__options__host
              value: "smtp.sendgrid.net"
            - name: mail__options__port
              value: "587"
            - name: mail__options__auth__user
              value: "apikey"
            - name: mail__options__auth__pass
              valueFrom:
                secretKeyRef:
                  name: sendgrid
                  key: ghost-api-key
          volumeMounts:
            - mountPath: /var/lib/ghost/content
              name: ghost-content
      volumes:
        - name: ghost-content
          persistentVolumeClaim:
            claimName: ghost-content

thedotedge avatar Nov 25 '21 12:11 thedotedge

Yeah, I posted about this a while back on the Ghost forums. Ghost's default configuration is definitely broken, even on a local install.

If you want to fix this temporarily, you can see how I fixed it here: Save Disk Space By Setting Up Logrotate with Your Ghost Blog

Currently, I'm busy, but I can look into patching this myself in the image later.

Torqu3Wr3nch avatar Jan 16 '22 19:01 Torqu3Wr3nch

This is managed by the config file when you start ghost. Per example - https://github.com/firepress-org/ghostfire/blob/master/config.production.json#L25

pascalandy avatar Apr 23 '22 22:04 pascalandy