I'm fairly new to bash scripting, but it feel like I'm really missing something basic here. I'm trying to a barely modified version of Mike Perham's upstart sidekiq script on an Ubuntu 14.04 machine, yet almost nothing is being evaluated as expected:
- export doesn't seem to be working
- source doesn't seem to evaluate my changed PATH variable in .bashrc or running the rbenv init command
- cd doesn't seem to change directories, unless the $(pwd) command isn't the correct way to evaluate it
Here's my modified script:
# /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
Here's the output I get in the upstart log file:
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
exec /bin/bash <<'EOT'
(hard quotes around the marker). Output should make more sense. – Cumquat