0

I have postfix email server with saslauthd. Time and again saslauthd daemon eats 100% CPU. Restarting these services returns to normal cpu usage.

Is there any proper script to determine services with high CPU usage and restart it automatically.

Thanks in advance.

Anand Shrestha
  • 41
  • 5
  • 12

1 Answers1

1

You might want to take a look at monit (official site).

It's easily configurable to watch for high CPU usage and restart processes when needed.

A simple example (you should configure it according to your system paths and needs):

check process saslauth with pidfile /var/run/saslauthd/saslauthd.pid
    group mail
    start program = "/etc/init.d/saslauthd start"
    stop program = "/etc/init.d/saslauthd stop"
    if cpu > 90% for 2 cycles then restart

Where (taken from the manual):

CPU([user|system|wait]) is the percent of time the system spend in user or 
kernel space and I/O. The user/system/wait modifier is optional, if not 
used, the total system cpu usage is tested

And a cycle is is equal to the number of seconds in the set daemon config options.

Daniele Santi
  • 2,529
  • 1
  • 25
  • 22
  • Is there any script to automate it ? I just want to run "systemctl restart saslauthd" as soon as it reaches 100% CPU. I am just slightly uncomfortable with monit. – Anand Shrestha Sep 07 '18 at 07:42
  • @AnandShrestha see my edits. It's all automatic if `monit` is configured right. You obviously need to use the correct paths and commands for your system. – Daniele Santi Sep 07 '18 at 07:44