monit:3: 구문 오류 '='

monit:3: 구문 오류 '='

충전을 중단하기 위해 프로그램이 완료되면 가상 머신이 종료되도록 설정하려고 합니다.

이를 위해 다음과 같은 .monitrc를 작성했습니다.

SET DAEMON 30
CHECK PROCESS py MATCHING /usr/bin/python3
    start program = "sudo /bin/systemctl poweroff -i"

monit을 실행하면 다음과 같이 응답합니다.

/home/baruch/.monitrc:3: 구문 오류 '='

monit-V 응답:

모니터-V

Monit 버전 5.20.0 입니다.

SSL, ipv6, 압축, pam 및 대용량 파일로 구축

운영 체제: Linux 인스턴스-1 4.9.0-11-amd64 #1 SMP Debian 4.9.189-3+deb9u1 (2019-09-20) x86_64

내 집 컴퓨터(Ubuntu 16.04, Monit 버전 5.16)에서 비슷한 .monitrc를 시도했는데 제대로 작동했습니다.

SET DAEMON 30
CHECK PROCESS py MATCHING /home/baruch/datasets/Severstal/.env/bin/python3
    start program = "/bin/systemctl poweroff -i"

도와주세요.

편집하다: 내 가상 머신이 설정된 방식은 systemctlsudo 없이는 작동하지 않기 때문에 sudo가 필요합니다 sudo(일부 자격 증명이 필요함). 하지만 sudo는 비밀번호가 필요하지 않으므로 .monitrc에서 사용할 수 있습니다.

분명히 monit은 시작 명령의 sudo에 해당 경로가 없다고 불평했습니다.

.monitrc를 다음과 같이 변경했습니다.

SET DAEMON 30
CHECK PROCESS py MATCHING /usr/bin/python3
start program = "/usr/bin/sudo /bin/systemctl poweroff -i"

이렇게 하면 monit은 오류 메시지를 표시하지 않지만 작동하지 않습니다.

log monit -l을 사용하여 실행해 보았더니 로그에 다음 내용만 포함되어 있습니다.

[10월 26일 20:27:31 UTC] 정보: Monit 5.20.0 데몬 시작

[10월 26일 20:27:31 UTC] 정보: "instance-1" Monit 5.20.0이 시작되었습니다.

[10월 26일 20:31:01 UTC] 정보: pid [1161]가 있는 Monit 데몬이 중지되었습니다.

[10월 26일 20:31:01 UTC] 정보: "instance-1" Monit 5.20.0이 중지되었습니다.

[10월 26일 20:31:20 UTC] 정보: Monit 5.20.0 데몬 시작

[10월 26일 20:31:20 UTC] 정보: "instance-1" Monit 5.20.0이 시작되었습니다.

[10월 26일 20:35:32 UTC] 정보: pid [1234]가 있는 Monit 데몬이 중지되었습니다.

[10월 26일 20:35:32 UTC] 정보: "instance-1" Monit 5.20.0이 중지되었습니다.

(여기서 멈추라는 것은 내가 주문한 것을 의미합니다 monit quit.)

어떤 도움이라도 대단히 감사하겠습니다.

답변1

다음과 같이 편집하십시오 monitrc(필요하지 않음 sudo).

start program = "/bin/systemctl poweroff -i"

man monit:

 By default the program is executed as the user under which Monit is
 running. If Monit is running as root, you may optionally specify the
 UID and GID the executed program should switch to.

Syntax:

 <START | STOP | RESTART> [PROGRAM] = "program"
         [[AS] UID <number | string>]
         [[AS] GID <number | string>]
         [[WITH] TIMEOUT <number> SECOND(S)]

예(맨페이지에서):

start program = "/usr/local/mmonit/bin/mmonit" as uid "mmonit" and gid "mmonit"

관련 정보