簡體   English   中英

每當gem cronjob無法從/ etc / environment加載PATH時

[英]Whenever gem cronjob not loading PATH from /etc/environment

在我的軌道上,我正在使用每時每刻的寶石來管理cron作業。 其中一個是:

* * * * * /bin/bash -l -c 'cd /home/myhome/analytics && RAILS_ENV=development /bundle exec rake my_rake_job'

但是它不起作用,並顯示錯誤/bin/bash: bundle: command not found

當我登錄的env從一個cronjob到一個文件,我可以在其他事之中看到兩個環境變量我申報/etc/environment (和其他地方),但PATH出來的只是PATH=/usr/bin:/bin ,而不是PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" /etc/environment文件。

我的意思是短期的骯臟解決方案是將ruby二進制文件(紅寶石,瑞克,rails,bundle等)符號鏈接到/usr/bin但這不是一個很好的解決方案。 為什么cron加載了一些var但沒有加載PATH

PS這是我的/etc/pam.d/cron文件

# The PAM configuration file for the cron daemon

@include common-auth

# Read environment variables from pam_env's default files, /etc/environment
# and /etc/security/pam_env.conf.
session       required   pam_env.so

# In addition, read system locale information
session       required   pam_env.so envfile=/etc/default/locale

@include common-account
@include common-session-noninteractive

# Sets up user limits, please define limits for cron tasks
# through /etc/security/limits.conf
session    required   pam_limits.so

使用可調的job_type每當配置參數來設置scheduler.rb bundle准確路徑:

job_type :rake, "cd :path && :environment_variable=:environment /usr/local/bin/bundle exec rake :task --silent :output"

最后,將source /etc/environment添加到.bash_profile (不是.bashrc )可確保cron用戶加載正確的變量,並且現在可以正常工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM