Using Monit 5.16 (stock package Ubuntu 16.04), this configuration:
Process Name = php7.1-fpm
Pid file = /var/run/php/php7.1-fpm.pid
Monitoring mode = active
Start program = '/usr/sbin/service php7.1-fpm start' timeout 30 second(s)
Stop program = '/usr/sbin/service php7.1-fpm stop' timeout 30 second(s)
Restart program = '/usr/sbin/service php7.1-fpm restart' timeout 30 second(s)
Existence = if does not exist then restart
Depends on Service = php7.1-fpm.log
Timeout = If restarted 3 times within 3 cycle(s) then unmonitor
File Name = php7.1-fpm.log
Path = /var/log/php7.1-fpm.log
Monitoring mode = active
Existence = if does not exist then restart
Content = if content = "segfault|SIGSEGV" then restart
makes monit crash as soon as the file match is met:
'php7.1-fpm.log' content match:
segfault
Sending Content match notification to [REDACTED]
Cannot create socket to [localhost]:25 -- Connection refused
Cannot open a connection to the mailserver 'localhost:25' -- Operation now in progress
Mail: No mail servers are available
Adding event to the queue file /var/monit/1590492063_6e1b60 for later delivery
'php7.1-fpm.log' trying to restart
'php7.1-fpm' stop: /usr/sbin/service
'php7.1-fpm' stopped
'php7.1-fpm.log' stop skipped -- method not defined
'php7.1-fpm.log' start method not defined
'php7.1-fpm.log' monitoring enabled
'php7.1-fpm.log' start method not defined
'php7.1-fpm.log' monitoring enabled
'php7.1-fpm.log' file exists
'php7.1-fpm.log' is a regular file or socket
'php7.1-fpm.log' Pattern 'segfault|SIGSEGV' doesn't match on content line [[26-May-2020 11:21:03] NOTICE: Terminating ...]
'php7.1-fpm.log' Pattern 'segfault|SIGSEGV' doesn't match on content line [[26-May-2020 11:21:03] NOTICE: exiting, bye-bye!]
'php7.1-fpm.log' content match:
segfault
Sending Content match notification to [REDACTED]
Cannot create socket to [localhost]:25 -- Connection refused
Cannot open a connection to the mailserver 'localhost:25' -- Operation now in progress
Mail: No mail servers are available
Adding event to the queue file /var/monit/1590492063_6e1b60 for later delivery
pidfile '/var/run/php/php7.1-fpm.pid' does not exist
'php7.1-fpm' start: /usr/sbin/service
'php7.1-fpm' started
AssertException: S && *S
raised in StringBuffer_free at src/util/StringBuffer.c:103
Thread 1 "monit" received signal SIGABRT, Aborted.
0x00007ffff6a28428 in __GI_raise (sig=sig@entry=6)
at ../sysdeps/unix/sysv/linux/raise.c:54
54 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0 0x00007ffff6a28428 in __GI_raise (sig=sig@entry=6)
at ../sysdeps/unix/sysv/linux/raise.c:54
#1 0x00007ffff6a2a02a in __GI_abort () at abort.c:89
#2 0x000000000041e460 in vLogAbortHandler ()
#3 0x000000000044bb25 in System_abort ()
#4 0x000000000044748f in Exception_throw ()
#5 0x000000000044fb18 in StringBuffer_free ()
#6 0x00000000004300fd in check_file ()
#7 0x000000000042f401 in validate ()
#8 0x000000000040c648 in main ()