如何在后台运行太阳黑子重新索引为每四个小时 [英] how to run sunspot reindex in background for every four hours

查看:169
本文介绍了如何在后台运行太阳黑子重新索引为每四个小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要执行耙太阳黑子:重新索引RAILS_ENV =为每四个小时生产指挥。要做到这一点我一直在使用shell编程写简单的bash脚本。我将在终端成功运行,但如果我想在crontab中运行它,然后它不工作。它现在用的操作系统是CentOS的。

I want to execute rake sunspot:reindex RAILS_ENV=production command for every four hours. To achieve this i have written simple bash script using shell programming. I will run successfully in terminal but if i tried to run it in crontab then it is not working. Operating system which am using is centos.

下面是我的bash脚本code

Here is my bash script code

#!/bin/bash
#export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH=/usr/local/rvm/gems/ruby-1.9.2-p290/bin:/usr/local/rvm/gems/ruby-1.9.2-p290@global/bin:/usr/local/rvm/rubies/ruby-1.9.2-p290/bin:/usr/local/rvm/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:
echo "started"
cd /var/www/html/spotchase2
pwd
source /usr/local/rvm/environments/ruby-1.9.2-p290
bundle install
if [ "$?" = 0 ]; then
    echo `date`
fi
source /usr/local/rvm/environments/ruby-1.9.2-p290
#/usr/local/rvm/gems/ruby-1.9.2-p290/bin/rake sunspot:reindex RAILS_ENV=production
rake sunspot:reindex RAILS_ENV=production
if [ "$?" = 0 ]; then
    echo "complete"
fi

请帮我解决这个问题。

修改

我重定向输出一个文本文件中。在该文本文件正在逐渐才开始,捆绑安装和日期。我没有得到完整的消息,所以我才知道,它不工作并在该文本文件我没有得到任何错误。

I am redirecting the output one text file. In that text file am getting only started, bundle install and date. Am not getting complete message, therefore i came to know that it is not working and am not getting any error on that text file.

请帮我解决这个问题。

推荐答案

通常情况下,我使用每当宝石来处理这样的事情。我没有写一个bash脚本,耙剧本是好的就够了。 每当将生成的crontab正确的语法。

Usually, I use the whenever gem to handle something like this. I don't have to write a bash script, a rake script is okay enough. Whenever will generate the correct syntax for crontab.

在我的项目,我有几个剧本需要在后台运行所有的时间。这里是产生contab文件的命令。

In my project, I have several script that need to be run in background all the time. Here is the command to generate contab file.

whenever --update-crontab --set environment=production --load-file config/schedule_client.rb --user ubuntu

和它会产生弄成这个样子。

And it will generate into something like this.

0 2 * * * /bin/bash -l -c 'source /home/ubuntu/.rvm/scripts/rvm && cd /var/www/yoolk_statistics_api && RAILS_ENV=production bundle exec rake statistics:generate_clienst --silent >> log/client.log 2>&1'

要确保我的crontab总是工作,我将输出重定向到日志文件,这样我可以看到它的运行与否。在我的Ubuntu的服务器,我通常检查 syslog文件进行调试。

To make sure my crontab always work, I redirect the output to the log file so that i can see it's running or not. In my ubuntu server, I usually check the syslog file for debugging.

这篇关于如何在后台运行太阳黑子重新索引为每四个小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆