Jos*_*osh 5 bash ubuntu upstart sidekiq ubuntu-14.04
我是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
Run Code Online (Sandbox Code Playgroud)
这是我在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
Run Code Online (Sandbox Code Playgroud)
Jos*_*osh 15
2变化完全不同:
1)向EOT添加硬报价exec /bin/bash << '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"
Run Code Online (Sandbox Code Playgroud)
我不知道为什么这两个变化有所不同,如果这与更新版本的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
Run Code Online (Sandbox Code Playgroud)