Monit removes quotation marks from program startup commands

I am debugging monit start / stop programs. In my /etc/monit.conf file, my start program statement looks like this:

 check process node with pidfile /home/ec2-user/blah/node.pid start program = "/bin/su -c 'export APP_ENV=development; /home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js start &> /tmp/monit.out ' " stop program = "/bin/su -c '/home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js stop'"" 

which I tested in a shell with

 $ sudo su # env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/sh # /bin/su -c '/usr/bin/env APP_ENV=development; /home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js start &> /tmp/monit.out ' 

executed this returns the correct output in the /tmp/monit.out file:

 Starting nodejs daemon... nodejs daemon started. PID: 16408 

But when I run sudo monit -v monitor node , it displays another command that is identical, with the exception of the remote internal single quotes :

 The service list contains the following entries: Process Name = node Pid file = /home/ec2-user/blah/node.pid Monitoring mode = active Start program = '/bin/su -c export APP_ENV=development; /home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js start &> /tmp/monit.out ' timeout 30 second(s) Stop program = '/bin/su -c /home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js stop' timeout 30 second(s) Existence = if does not exist 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert Pid = if changed 1 times within 1 cycle(s) then alert Ppid = if changed 1 times within 1 cycle(s) then alert System Name = system_ip-xx-xx-xx-xx.ec2.internal Monitoring mode = active 

I cannot find anything about this in the monit documentation. The documentation here seems to be the final link, but does not go through the source code, I'm not sure what to do next.

My team works fine without removing quotes, so I just need to fix this problem. All ideas and possible corrections are welcome.

+6
source share
2 answers

This is a rather late answer, however, I find it important, as it causes some misunderstanding (therefore I was misled)

You do not need to avoid a single quote character. Try:

 check process fake_proc with pidfile /tmp/test_pid start = "/bin/bash -c 'echo $$ > /tmp/test_pid'" stop = "echo stop > /tmp/test_pid" 

It will not be displayed as a running process, however a test_pid file is test_pid . Add ; sleep xx ; sleep xx to catch a process and examine its properties.

The problem may be caused by some problem related to env.

+2
source

Put the "start program" and "stop program" commands in the script shell, make it executable, and then specify your address for monit.

try to avoid single quote using slash

\ '

(I have not tried, so I don’t know if it works).

0
source

Source: https://habr.com/ru/post/950608/


All Articles