我一直在使用monit/mmonit来监视我的系统。如果它的一个特性是check program语法,它运行一个程序并验证它的返回值:
# Asserts that there are more than 40 users in the DEV DB.
check program more_than_40_users_in_dev_db
with path /home/ubuntu/servers-scripts/monitoring/more_than_40_users_in_dev_db.py
with timeout 5 seconds
every 2 cycles
if status != 0 then alert问题是脚本应该以用户ubuntu的身份运行,但是monit以root的形式运行。我尝试过as uid ubuntu and gid ubuntu语法,但它似乎不适用于check program指令。
是否有办法以特定用户的身份运行此脚本?
发布于 2020-09-04 22:08:17
在这几年中,这种情况可能发生了变化,但只要monit作为root运行(例如,systemd服务),就可以用as uid abc and as gid abc语法来实现这一点:
# You can also shorten to 'as gid user and uid user'; both formats work for me with v5.26.0
check program somescript with path /home/user/somescript.sh as gid user and as uid user
if status != 0 then alertsomescript.sh在哪里
#!/bin/bash
whoami > /home/user/whoami.out当然,您也可以使用用户所属的另一个gid (例如sharing),生成的文件将使用所有权user:sharing创建,并包含“user”。
https://serverfault.com/questions/630224
复制相似问题