How to configure a Linux service to start automatically after a crash.

Under the [Service] section of let’s say Postfix in the file /usr/lib/systemd/system/postfix.service add the following 2 lines:

Restart=always
RestarSec=5

Then you need to reload the daemon configurations to ensure systemd is aware of this change by doing:

systemctl daemon-reload
systemctl restart postfix.service

server:~ # ps aux | grep postfix
root     24446  0.0  0.0  34180  3216 ?        Ss   12:53   0:00 /usr/lib/postfix/bin//master -w
postfix  24447  0.0  0.1  35820  3996 ?        S    12:53   0:00 pickup -l -t fifo -u
postfix  24448  0.0  0.1  36204  5732 ?        S    12:53   0:00 qmgr -l -t fifo -u
root     24523  0.0  0.0   9288  1636 pts/0    S+   13:08   0:00 grep --color=auto postfix
server:~ # kill -9 24446
server:~ # ps aux | grep postfix
root     24549  0.0  0.0   9288  1636 pts/0    S+   13:08   0:00 grep --color=auto postfix
server:~ # ps aux | grep postfix
root     24644  0.0  0.0  34180  3216 ?        Ss   13:08   0:00 /usr/lib/postfix/bin//master -w
postfix  24645  0.0  0.1  35820  3992 ?        S    13:08   0:00 pickup -l -t fifo -u
postfix  24646  0.0  0.1  36204  5732 ?        S    13:08   0:00 qmgr -l -t fifo -u
root     24662  0.0  0.0   9288  1632 pts/0    S+   13:08   0:00 grep --color=auto postfix
server:~ #



Leave a Reply

Your email address will not be published. Required fields are marked *

*