mailtrain icon indicating copy to clipboard operation
mailtrain copied to clipboard

Ownership of server/files/* changed to root:root on every restart

Open ghost opened this issue 4 years ago • 2 comments

The ownership of server/files/* is being changed to root:root on every Mailtrain restart.

$ ls -l /opt/mailtrain/server/files/
total 16
drwxr-xr-x 4 mailtrain mailtrain 4096 May 17  2021 cache
drwxr-xr-x 2 mailtrain mailtrain 4096 Dec  8 10:52 imports
drwxr-xr-x 2 mailtrain mailtrain 4096 Jun  2  2021 reports
drwxr-xr-x 2 mailtrain mailtrain 4096 Dec  8 10:52 uploaded
$ sudo systemctl restart mailtrain
$ ls -l /opt/mailtrain/server/files/
total 16
drwxr-xr-x 4 root root 4096 May 17  2021 cache
drwxr-xr-x 2 root root 4096 Dec  8 10:52 imports
drwxr-xr-x 2 root root 4096 Jun  2  2021 reports
drwxr-xr-x 2 root root 4096 Dec  8 10:52 uploaded

File uploads (for list imports) start to fail after this change as the mailtrain user can no longer write to these locations. At the moment I have to remember to run sudo chown -R mailtrain:mailtrain /opt/mailtrain/server/files/* after every restart.

The ownership change appears to happen on line 94 of server/index.js. https://github.com/Mailtrain-org/mailtrain/blob/d89d5d0e7249f95890e7b8c52ebbbc85e308c3bb/server/index.js#L91-L95


I have a Mailtrain instance (updated to d89d5d0) running on a Debian 10 machine, installed manually without Docker.

ghost avatar Dec 08 '21 13:12 ghost

I'm not confident enough with the Mailtrain codebase (or Node in general) to fix the issue there so I've worked around it as per below - in case it helps anyone else.

  1. In systemd service file:
    • changed Type from simple to notify
    • Added ExecStartPost=chown -R mailtrain:mailtrain /opt/mailtrain/server/files/
  2. Installed sd-notify in server/
  3. Modified server/index.js as below
diff --git a/server/index.js b/server/index.js
index 2fb88cc..754c7d9 100644
--- a/server/index.js
+++ b/server/index.js
@@ -24,6 +24,7 @@ const shares = require('./models/shares');
 const { AppType } = require('../shared/app');
 const builtinZoneMta = require('./lib/builtin-zone-mta');
 const klawSync = require('klaw-sync');
+const sdNotify = require('sd-notify');
 
 const { uploadedFilesDir } = require('./lib/file-helpers');
 const { reportFilesDir } = require('./lib/report-helpers');
@@ -123,6 +124,7 @@ async function init() {
 
     log.info('Service', 'All services started');
     appBuilder.setReady();
+    sdNotify.ready();
 }
 
 init().catch(err => {log.error('', err); process.exit(1); });

Steps 2 and 3 are there so that the ExecStartPost command is run once Mailtrain has finished starting up.

ghost avatar Dec 23 '21 13:12 ghost

Also this happened to me last year in one deployment, it was fixed after many hours of work, the solution was install the "posix" node module correctly

anibalpacheco avatar Oct 12 '23 06:10 anibalpacheco

We are going to start with the development and testing of mailtrain v3 in the next weeks.

You are welcome to help us with the testing as soon as the first release candidate is available.

forgeOneHQ avatar Mar 16 '24 09:03 forgeOneHQ