簡體   English   中英

Ubuntu 14.04上的upstart或bash腳本是否有變化? (嘗試用upstart啟動sidekiq)

[英]Did upstart or bash scripts change on Ubuntu 14.04? (Trying to boot sidekiq with upstart)

我是bash腳本的新手,但我覺得我真的錯過了一些基本的東西。 我正在嘗試在Ubuntu 14.04機器上幾乎沒有修改版本的Mike Perham的新貴sidekiq腳本 ,但幾乎沒有按預期評估任何內容:

  • 出口似乎沒有起作用
  • source似乎沒有在.bashrc中評估我更改的PATH變量或運行rbenv init命令
  • cd似乎沒有更改目錄,除非$(pwd)命令不是評估它的正確方法

這是我修改過的腳本:

# /etc/init/sidekiq.conf - Sidekiq config

# This example config should work with Ubuntu 12.04+.  It
# allows you to manage multiple Sidekiq instances with
# Upstart, Ubuntu's native service management tool.

# change to match your deployment user
setuid deploy
setgid deploy

stop on (stopping workers or runlevel [06])

respawn
respawn limit 3 30

instance $index

script
# this script runs in /bin/sh by default
# respawn as bash so we can source in rbenv
exec /bin/bash <<EOT
  # use syslog for logging
  # exec &> /dev/kmsg

  # pull in system rbenv
  export HOME=/home/deploy
  echo "home is $HOME"
  source /home/deploy/.bashrc
  echo "path is $PATH"

  cd /home/deploy/domain_freek/current
  echo "user is $(whoami) and pwd is $(pwd) and rbenv is located at $(which rbenv)"
  exec bundle exec sidekiq -i ${index} -e production
EOT
end script

這是我在upstart日志文件中得到的輸出:

home is
path is /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
user is deploy and pwd is / and rbenv is located at 
/bin/bash: line 12: exec: bundle: not found

2變化完全不同:

1)在exec /bin/bash << 'EOT'向EOT添加硬報價(信用到Mat,謝謝!)

2)不使用source加載.bashrc,而是將.bashrc中的rbenv行直接添加到upstart腳本中。 source /home/deploy/.bashrc替換為:

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"

我不知道為什么這兩個變化有所不同,如果這與更新版本的ubuntu,upstart或bash有關。 如果有人可以解釋,請加入。

我已經為所有尋找答案的人提供了完整的工作腳本:

# /etc/init/sidekiq.conf - Sidekiq config

# This example config should work with Ubuntu 12.04+.  It
# allows you to manage multiple Sidekiq instances with
# Upstart, Ubuntu's native service management tool.
#
# See workers.conf for how to manage all Sidekiq instances at once.
#
# Save this config as /etc/init/sidekiq.conf then mange sidekiq with:
#   sudo start sidekiq index=0
#   sudo stop sidekiq index=0
#   sudo status sidekiq index=0
#
# or use the service command:
#   sudo service sidekiq {start,stop,restart,status}
#

description "Sidekiq Background Worker"

# no "start on", we don't want to automatically start
stop on (stopping workers or runlevel [06])

# change to match your deployment user
setuid deploy
setgid deploy

respawn
respawn limit 3 30

# TERM is sent by sidekiqctl when stopping sidekiq.  Without declaring these as normal exit codes, it just respawns.
normal exit 0 TERM

instance $index

script
# this script runs in /bin/sh by default
# respawn as bash so we can source in rbenv
exec /bin/bash << 'EOT'
  # use syslog for logging
  # exec &> /dev/kmsg

  # pull in system rbenv
  export HOME=/home/deploy
  echo "$HOME"
  #source /home/deploy/.bashrc
  export PATH="$HOME/.rbenv/bin:$PATH"
  eval "$(rbenv init -)"
  export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
  echo "$PATH"

  cd /home/deploy/domain_freek/current
  echo "user is $(whoami) and pwd is $(pwd) and rbenv is located at $(which rbenv)"  
  exec bundle exec sidekiq -i ${index} -e production
EOT
end script

如果shell以非交互模式運行,Ubuntu 14.04上的默認.bashrc文件有幾行可立即返回。 當您從bashrc中刪除這些行時, source將在upstart中按預期工作。

〜/ .bashrc (要刪除的行)

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

Josh的解決方案在使用rbenv的ubuntu 14.04上對我不起作用。 然而這確實有效:

exec /bin/bash <<EOF
  export RBENV_ROOT=/home/ubuntu/.rbenv
  export RBENV_VERSION=2.2.2
  cd /var/www/app/current
  exec /home/ubuntu/.rbenv/bin/rbenv exec bundle exec sidekiq -i ${index} -e production
EOF

暫無
暫無

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

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