[英]Did upstart or bash scripts change on Ubuntu 14.04? (Trying to boot sidekiq with upstart)
我是bash腳本的新手,但我覺得我真的錯過了一些基本的東西。 我正在嘗試在Ubuntu 14.04機器上幾乎沒有修改版本的Mike Perham的新貴sidekiq腳本 ,但幾乎沒有按預期評估任何內容:
這是我修改過的腳本:
# /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.