I have installed the stalwart-mail https://github.com/stalwartlabs email server on a postgres appliance. There is a service present in /etc/systemd/system/stalwart-mail.service. However I cannot figure out how to launch the service at start-up. I've tried systemctl enable stalwart-mail.service but this did not work. Is there something specific I have to do for a turnkey appliance? Thanks Paul
Forum: 
Jeremy Davis's picture

Assuming that 'systemctl start stalwart-mail.service' makes it run manually, 'systemctl enable stalwart-mail.service' should make it auto start at boot time. So I assume that something is causing it to fail to start at boot. My guess is that it's trying to start too early - perhaps before networking has been configured, or something else it depends on.

If I'm correct and you can work out what it needs to wait for, then the service file can be adjusted to ensure that it only starts after whatever it depends on has already started.

The first thing I'd suggest is checking the journal and see if anything jumps out there. To get all messages related to the stalwart service since the last boot:

journalctl -b -u stalwart-mail.service

If that's too noisy and/or nothing jumps out, I recommend rebooting and straight away check the status; 'systemctl status stalwart-mail.service'. Hopefully that will confirm my suspicion and might give some useful info on why it failed. That will only show the last few lines of log, so if you can't see anything there, I'd the journal again (as above).

It might also be useful to manually start it and compare the log entries from the initial (failed) start at boot time vs the successful start after boot.

If you need more guidance, post back with log info. It would also be useful to see a copy of the service file too. Even if you do get it to work yourself, it'd be great if you could share a bit about how you fixed it.

Jeremy Davis's picture

I've just had a quick poke around in their repo - specifically looking at their install script. I'm guessing that you used that to install? So you have their default 'stalwart-mail.service'?

Assuming so, then it should wait for networking to start. But I see that it conflicts with postfix. We have postfix enabled by default to send system emails. If postfix starts first, then it should work because stalwart-mail.service will kill it. But if it starts before postfix, then I suspect that postfix will kill stalwart instead! That would certainly explain why it works ok when started manually but not at boot.

TL;DR if my above troubleshooting steps (i.e. my previous post) don't show anything obvious - or they confirm my latest suspicion - then try disabling postfix (systemctl disable postfix), reboot and see if that helps.

systemctl status stalwart-mail.service
stalwart-mail.service - Stalwart Mail Server                                                                                                                                                             Loaded: loaded (;;file://postgresql/etc/systemd/system/stalwart-mail.service/etc/systemd/system
stalwart-mail.service;;; enabled; preset: enabled)
Active: inactive (dead)
So it was being killed by postfix
systemctl disable postfix
Synchronizing state of postfix.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable postfix 
Removed "/etc/systemd/system/multi-user.target.wants/postfix.service".
Bingo.

Cheers, Paul

Contents of service file as follows

[Unit]
Description=Stalwart Mail Server
Conflicts=postfix.service sendmail.service exim4.service
ConditionPathExists=/opt/stalwart-mail/etc/config.toml
After=network-online.target

[Service]
Type=simple
LimitNOFILE=65536
KillMode=process
KillSignal=SIGINT
Restart=on-failure
RestartSec=5
ExecStart=/opt/stalwart-mail/bin/stalwart-mail --config=/opt/stalwart-mail/etc/config.toml
SyslogIdentifier=stalwart-mail
User=stalwart-mail
Group=stalwart-mail
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

Sorry about formatting. Can't see how to edit comment.

Jeremy Davis's picture

Firstly, glad to hear that fixed the issue! :)

I updated the formatting in your earlier post so that's all good.

Because of our crappy old website, to format posts you have 2 options:

  1. Use inline html tags (i.e. write raw html) - which is the default; or
  2. Select plain text from the "Text format" drop down (below the text entry box)

Either are a bit of a PITA. #2 (plain text) is probably easier - particularly if you aren't that familiar with html. Although unfortunately it has to be manually selected each time you post ("Filtered HTML" is the default).

The default "Filtered HTML" (#1) is a bit more involved and only supports a subset of html - the supported options should be noted the drop down - but it does support code blocks. The common tags are <p> to start a new paragraph, <pre> for a code block (code blocks honor newlines but need to be closed with a trailing </pre>), <h1>/<h2>/etc (with closing </h1>/</h2>/etc) for headings, <b> & <i> for bold and italic respectively (again with closing </b> or <h2>).

So if I were you, I'd probably just select plain text. If you do want to format a code block then you need to do the whole post in html although I'd just use the <p> (to separate text into paragraphs) and <pre> & <pre> for the code block/s. No need to worry about the others (unless you really want to).

Or just wait for me to fix it! :)

Add new comment