Cron 作业 openshift 错误

Cron job openshift error

我有一个 rails 4 openshift 应用程序。我正在尝试 运行 一个 cron 作业。当我 运行 它本身时,脚本 运行 完全没问题。脚本是:

#!/bin/bash
/bin/bash -l -c 'cd $OPENSHIFT_REPO_DIR && bundle exec bin/rails runner -e production "Payment.charge_customers_pay_experts"'

问题是日志文件给我以下错误

Wed Feb  3 22:57:05 EST 2016: START minutely cron run
__________________________________________________________________________
/var/lib/openshift/56a438107628e18b30000111/app-root/runtime/repo//.openshift/åcron/minutely/charge_customers_pay_experts:
Warning: You're using Rubygems 2.0.14 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.
/var/lib/openshift/56a438107628e18b30000111/app-root/runtime/repo/vendor/bundle/ruby/gems/spring-1.6.2/lib/spring/sid.rb:39:in `getpgid': Permission denied (Errno::EACCES)
from /var/lib/openshift/56a438107628e18b30000111/app-root/runtime/repo/vendor/bundle/ruby/gems/spring-1.6.2/lib/spring/sid.rb:39:in `pgid'
from /var/lib/openshift/56a438107628e18b30000111/app-root/runtime/repo/vendor/bundle/ruby/gems/spring-1.6.2/lib/spring/server.rb:78:in `set_pgid'
from /var/lib/openshift/56a438107628e18b30000111/app-root/runtime/repo/vendor/bundle/ruby/gems/spring-1.6.2/lib/spring/server.rb:34:in `boot'
from /var/lib/openshift/56a438107628e18b30000111/app-root/runtime/repo/vendor/bundle/ruby/gems/spring-1.6.2/lib/spring/server.rb:14:in `boot'
from -e:1:in `<main>'
__________________________________________________________________________
Wed Feb  3 22:57:06 EST 2016: END minutely cron run - status=0
__________________________________________________________________________

我已经确定脚本是可执行的。我不确定我是否遗漏了什么。有人有什么想法吗?

我不知道脚本可执行与此有什么关系。看起来更像是权限错误。 运行 执行 cron 作业的系统用户是否具有 运行 的正确权限?您可以通过登录该用户(或 sudo su - <user>)来测试它,然后手动执行脚本中的命令。

/bin/bash -l -c 'cd $OPENSHIFT_REPO_DIR && bundle exec bin/rails runner -e production "Payment.charge_customers_pay_experts"'

请务必将 $OPENSHIFT_REPO_DIR 变量替换为您的 OpenShift 存储库目录的正确路径。

您可能只需要将您的 cronjob 运行s 用户添加到对文件具有权限的组,或者 运行 cronjob 作为更高特权的用户(在它对所需文件具有权限)。

顺便说一句,我只能 post 作为答案,因为 Stack Overflow 告诉我我需要 50 个信誉点才能发表评论。

我通过在我的 gem 文件中注释掉 'spring' gem 来解决这个问题。但显然这是一个已知问题。 https://bugzilla.redhat.com/show_bug.cgi?id=1305544.

在解决此问题之前,暂时有解决方法。您可以编辑 /usr/libexec/openshift/cartridges/cron/bin/cron_runjobs.sh 以在 timeout 前面添加 setsid 以便它运行 setsid timeout ... 因为这允许超时命令实际更改 sid.