![](/img/trans.png)
[英]Running gitlab version > 15, gives an error: [migrate gitlab-rails database] had an error: Mixlib::ShellOut::ShellCommandFailed
[英]How to run a cron script with gitlab-rails
我有 gitlab-rails
我想从 Cron 运行一个 gitlab-rails 脚本。 gitlab-rails runner
似乎已损坏,因为它无法识别文件参数并尝试将其作为脚本运行,但失败了。 因此,即使gitlab-rails runner -h
中建议的 shebang 行有效(它在我的系统上没有,因为 args 没有分开), gitlab-rails runner 抱怨文件路径不是有效的脚本。
我可以将 ruby 脚本包含在 shell 脚本中,pipe 将它添加到 gitlab-rails,但牺牲.rb 文件语法高亮和智能感知
我可以将 shell 脚本中的.rb
脚本 pipe 放入 gitlab-rails。 这将解决以前的问题,但是现在我有两个脚本,并且 shell 在引用相关脚本时不可靠,除非我明确地给它库路径。 这似乎令人费解。
有人提出了解决方法。 它包括像往常一样运行 ruby,然后使用 rails 重新执行脚本(在我的例子中是 gitlab-rails)。 这仍然失败,因为损坏的 gitlab-rails 运行程序将文件参数视为 rails 命令......
我已经将解决方法扩展到 pipe 脚本到标准输入上的 gitlab-rails 确实有效:
#!/usr/bin/env ruby
#
# List GitLab projects
#
# Run this script with sudo
if not defined?(Rails) then
# Running in plain rubby, invoke rails runner and pipe the script into it, passing args
exec("/usr/bin/gitlab-rails", "runner", "-", *ARGV, :in=>[File.expand_path(__FILE__)])
end
# Do your GitLab work here. This is just a harmless trivial example.
Project.find_each do |project|
puts "#{project.full_path}"
end
使此脚本可执行chown a+x
后,我可以方便地将其放入 cron 作业中:
00 * * * * root /path/to/my/script.rb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.