Monit和/ etc / environment

时间:2017-09-03 09:36:38

标签: bash monit

我在RAILS_ENV='production'中设置了/etc/environment变量,以及简单的bash脚本

#!/bin/bash
printenv

在monit配置中,我检查这个脚本是否正在运行。(它仅用于测试目的,因为没有这样的过程,monit应该尝试启动它:

start program = "/home/deploy/www/laptophits/current/bin/importer"

我在monit日志中收到错误:

[UTC Sep  3 09:31:50] error    : 'importer' failed to start (exit status 0) -- /home/deploy/www/laptophits/current/bin/importer: MONIT_DATE=Sun, 03 Sep 2017 09:31:20
MONIT_HOST=localhost
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
LANG=en_US.UTF-8
MONIT_PROCESS_PID=-1
MONIT_EVENT=Started
MONIT_PROCESS_MEM

所以看起来这个bash脚本只运行一些简单的monit变量。如何使其与/etc/variables和/或用户变量一起运行?

2 个答案:

答案 0 :(得分:0)

您可以将命令运行为:

start program = "/bin/bash -c '/home/deploy/www/laptophits/current/bin/importer'" as uid **username** and gid **group**

shell将加载用户的环境。

答案 1 :(得分:0)

要在monit中加载/ etc / environment变量,您必须使用source /etc/environment

例如

  start program = "/bin/bash -c 'source /etc/environment && cd /srv/<project>/current && /usr/local/rbenv/shims/bundle exec sidekiq -d -L log/sidekiq.log -C config/sidekiq.yml -e production'" as uid 1000 and gid 1000

这将加载用户环境和/ etc / environment文件。