✓ Solved

How do i automatically start Postfix?

Currently I have postfix setup and ready to go on Ubuntu 23.04! It runs very well, currently I can send and recieve emails. But theres one tiny problem, I have to run the command below after every reboot.

sudo postfix start

I have tried enabling the postfix service with the command below

sudo systemctl enable postfix

And on each boot it shows that its active and running:

● postfix.service - Postfix Mail Transport Agent
  Loaded: loaded (/lib/systemd/system/postfix.service; enabled; 
  preset: enabled)
  Active: active (exited) since Tue 2023-09-26 05:26:41 UTC; 24min 
  ago
    Docs: man:postfix(1)
 Process: 716 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 716 (code=exited, status=0/SUCCESS)
     CPU: 623us

Sep 26 05:26:41 user systemd[1]: Starting postfix.service 
- Postfix Mail Transport Agent...
Sep 26 05:26:41 user systemd[1]: Finished postfix.service 
- Postfix Mail Transport Agent.

But even with the service running whenever I enter:

sudo postfix status

It outputs:

postfix/postfix-script: the Postfix mail system is not running

Now at this point is when if i manually enter the command below after booting up:

sudo postfix start

That I now get to see the output below which means everything is running fine.

postfix/postfix-script: warning: /var/spool/postfix/etc/resolv.conf and /etc/resolv.conf differ
postfix/postfix-script: starting the Postfix mail system

I've tried creating a startup.sh script which sleeps for 100 seconds and then runs "sudo postfix start", now (in theory) well after the server has loaded everything it will start postfix in a manner similar to if i were to have typed it in manually:

#!/bin/bash

# Start Postfix
bash -c "sleep 100 && sudo postfix start"

in my syslog file ill paste a snippet of what it shows…

2023-09-26T05:27:57.686798+00:00 user systemd[728]: Startup 
finished in 75ms.

2023-09-26T05:27:57.694322+00:00 user snapd-aa-prompt-ui[742]: 
AA Prompt UI not implemented

2023-09-26T05:28:14.499098+00:00 user postfix/postfix- 
script[897]: warning: /var/spool/postfix/etc/resolv.conf and         
/etc/resolv.conf differ

2023-09-26T05:28:14.596741+00:00 user postfix/postfix- 
script[1046]: starting the Postfix mail system

2023-09-26T05:28:14.601022+00:00 user postfix/master[1048]: 
daemon started -- version 3.7.4, configuration /etc/postfix

2023-09-26T05:28:14.603496+00:00 user postfix/master[1048]: 
terminating on signal 15

2023-09-26T05:28:14.604461+00:00 user systemd[1]: 
startup.service: Deactivated successfully.

Here you can see that a bit after the system has launched everything else, I get the "starting the Postfix mail system" output that we saw earlier from when i started it manually. The unfortunate part is that after checking postfix with

sudo postfix status

It outputs…

postfix/postfix-script: the Postfix mail system is not running

Something i did notice in my syslog was this output

2023-09-26T05:28:14.603496+00:00 user postfix/master[1048]: 
terminating on signal 15

how would i go about troubleshooting that? Could there be other problems non related to the output that may be causing problems? (i'm kind of a noob) Thank you!

5 Replies

✓ Best Answer

while i'm not sure what went wrong with my initial setup, rebuilding my linode server and reconfiguring it now has it working, thanks!

if i just run the startup script without waiting the 100 seconds:

#!/bin/bash

# Start Postfix
#bash -c "sleep 100 && sudo postfix start"
sudo postfix start

then when it runs it outputs something similar, just at a different time. I will however paste more info about postfix from the syslog after a reboot, hopefully that can help with troubleshooting

2023-09-26T06:45:05.259581+00:00 user postfix/master[1282]: 
terminating on signal 15

2023-09-26T06:45:05.276213+00:00 user systemd[1]: Removed 
slice system-postfix.slice - Slice /system/postfix.

2023-09-26T06:46:36.057074+00:00 user kernel: [    3.832711] 
systemd[1]: Created slice system-postfix.slice - Slice 
/system/postfix.

2023-09-26T06:46:36.614290+00:00 user postfix/postfix- 
script[721]: warning: /var/spool/postfix/etc/resolv.conf and 
/etc/resolv.conf differ

2023-09-26T06:46:36.909474+00:00 user postfix/postfix- 
script[874]: starting the Postfix mail system

2023-09-26T06:46:36.918248+00:00 user postfix/master[877]: 
daemon started -- version 3.7.4, configuration /etc/postfix

2023-09-26T06:46:36.929564+00:00 user postfix/master[877]: 
terminating on signal 15

2023-09-26T06:46:48.500266+00:00 user systemd[1]: Starting 
postfix@-.service - Postfix Mail Transport Agent (instance -)...

2023-09-26T06:46:48.611351+00:00 user systemd[1]:         
postfix@-.service: Control process exited, code=exited,     
status=1/FAILURE

2023-09-26T06:46:48.611767+00:00 user systemd[1]: 
postfix@-.service: Failed with result 'exit-code'.

2023-09-26T06:46:48.611825+00:00 user systemd[1]: Failed to start 
postfix@-.service - Postfix Mail Transport Agent (instance -).

2023-09-26T06:46:48.617253+00:00 user systemd[1]: Starting 
postfix.service - Postfix Mail Transport Agent...

2023-09-26T06:46:48.617897+00:00 user systemd[1]: Finished 
postfix.service - Postfix Mail Transport Agent.

Although we have host access, I wasn't able to see any definitive causes for the issue. I was able to confirm that although you have correctly enabled Postfix to (attempt to) start on boot, it was failing to restart on your test reboots.

Working our way down, I would first start by checking our general Postfix Troubleshooting guide:

That guide recommends checking your error logs, which can be done by running the command:

tail -f /var/log/mail.log

Otherwise, something in your system is sending a Terminate Signal 15 to kill the Postfix application process. I found a StackOverflow forum post about this issue that might prove helpful:

While I found some similar posts on ServerFault:

I didn't see an OOM Kill (Out of Memory) in your host error logs, but only store your previous and most recent boot history, so excessive reboots would clear this from our view. It could also be worth updating your system and applications to ensure a versioning issue isn't the cause:

sudo apt update && sudo apt upgrade -y

i see what you mean by "I was able to confirm that although you have correctly enabled Postfix to (attempt to) start on boot, it was failing to restart on your test reboots." when i run

sudo systemctl stop postfix

followed by

sudo systemctl start postfix

my output is:

2023-09-26T06:46:48.611351+00:00 user systemd[1]:         
postfix@-.service: Control process exited, code=exited,     
status=1/FAILURE

I purged postfix, mailutils, and courier-imap then reinstalled them to try to get a clean try to stop/start postfix and it still gives me the error. I installed ubuntu 23.04 on a VMBox and tried running things and it doesnt give an error. So i will wipe my linode server run it back fresh and see where that takes me.

Thank you for answering.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct