繁体   English   中英

Sidekiq不要在EC2服务器重新启动时启动

[英]Sidekiq donot start on ec2 server reboot

我已经使用centos在ec2 rails服务器中部署了我的网站。 EC2服务器重新启动时如何运行sidekiq? 我遵循了这个http://dxta.github.io/blog/2014/03/06/init-script-for-sidekiq-in-centos/ ,我写了一个如下的bash脚本,但是sidekiq不会按预期重新启动

"#! /bin/bash
#
# sidekiq Init script for sidekiq
#
# chkconfig: 345 99 1
# description: Starts and stops sidekiq message processor

# Source function library.
# . /etc/rc.d/init.d/functions

# You will need to modify these
APP=""sps_qa""
AS_USER=""ec2-user""
APP_DIR=""/home/ec2-user/www/sps_qa/current""

APP_CONFIG=""/home/ec2-user/www/sps_qa/current/config""
LOG_FILE=""/home/ec2-user/www/sps_qa/current/log/sidekiq.log""
LOCK_FILE=""$APP_DIR/${APP}-lock""
PID_FILE=""$APP_DIR/${APP}.pid""
GEMFILE=""$APP_DIR/Gemfile""
SIDEKIQ=""sidekiq""
APP_ENV=""qa""
BUNDLE=""bundle""

# [ -e /etc/sysconfig/sidekiq-your_app ] && . /etc/sysconfig/sidekiq-     your_app

START_CMD=""exec ~/.rvm/bin/rvm-shell -c '$BUNDLE exec $SIDEKIQ -q mailer -q default -e $APP_ENV -P $PID_FILE'""
CMD=""source /home/ec2-user/.rvm/scripts/rvm; cd ${APP_DIR}; ${START_CMD} >> ${LOG_FILE} 2>&1 &""

RETVAL=0
start() {

  status
  if [ $? -eq 1 ]; then

[ `id -u` == '0' ] || (echo ""$SIDEKIQ runs as root only ..""; exit 5)
[ -d $APP_DIR ] || (echo ""$APP_DIR not found!.. Exiting""; exit 6)
    cd $APP_DIR
   echo ""Starting $SIDEKIQ message processor .. ""

    su -c ""$CMD"" - $AS_USER

    RETVAL=$?
    #Sleeping for 8 seconds for process to be precisely visible in process table - See status ()
    sleep 8
    [ $RETVAL -eq 0 ] && touch $LOCK_FILEd
"
return $RETVAL
  else
    echo "$SIDEKIQ message processor is already running .. "
  fi


}

stop() {

    echo "Stopping $SIDEKIQ message processor .."
    SIG="INT"
    kill -$SIG `cat  $PID_FILE`
    RETVAL=$?
    [ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
    return $RETVAL
}
status() {

  ps -ef | grep 'sidekiq [0-9].[0-9].[0-9]' | grep -v grep
  return $?
}

restart() {
  stop
  start
}

reload() {
  restart
}

force_reload() {
case "$1" in
    start)


    stop)


    restart)
  ;;
    reload)
  ;;
    force_reload)
  ;;
    status)

       status

        if [ $? -eq 0 ]; then
         echo "$SIDEKIQ message processor is running .."
         RETVAL=0
     else
         echo "$SIDEKIQ message processor is stopped .."
         RETVAL=1
     fi

*)

    exit 0

esac
exit $RETVAL

目前,我正在手动运行sidekiq。 捆绑exec sidekiq -q mailer -q默认-e qa -d -L /home/ec2-user/www/sps_qa/current/log/sidekiq.log 2>&1

创建一个新贵的作业,以便在启动过程中触发sidekiq。 在sidekiq Wiki中有一个示例。 更改参数以匹配您的参数。 https://github.com/mperham/sidekiq/blob/master/examples/upstart/manage-one/sidekiq.conf

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM