2014-10-18 11 views
5

Sono abbastanza nuovo per bash scripting, ma mi sento come se mi mancasse davvero qualcosa di base qui. Sto cercando di una versione modificata del malapena Mike Perham's upstart sidekiq script su una macchina Ubuntu 14.04, ma quasi nulla è in corso di valutazione come previsto:Gli script upstart o bash sono cambiati su Ubuntu 14.04? (Cercando di avviare sidekiq con upstart)

  • esportazione non sembra funzionare
  • fonte non sembra per valutare la mia variabile PATH cambiato nel .bashrc o eseguendo il comando rbenv init
  • cd non sembra cambiare le directory, a meno che il comando $ (pWD) non è il modo corretto per valutarlo

Ecco la mia script modificato:

# /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 

ecco l'output ottengo nel file di registro parvenu:

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 
+3

Provare 'exec/bin/bash << 'EOT'' (virgolette sull'indicatore). L'output dovrebbe avere più senso. – Mat

+0

OK! Grazie, le virgolette sono state d'aiuto. Ora HOME viene esportato e cd cambia effettivamente la directory ... Ora devo solo capire come caricare correttamente il file .bashrc, o inizializzare rbenv in un altro modo – Josh

risposta

15

2 Modifiche fatto la differenza:

1) Aggiungere citazioni duri per EOT in exec /bin/bash << 'EOT' (credito per Mat, grazie!)

2) Invece di caricare .bashrc utilizzando il codice sorgente, aggiungere le righe rbenv da .bashrc direttamente allo script di avvio. Sostituire source /home/deploy/.bashrc con:

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

Non ho idea del perché quei due modifiche hanno fatto la differenza, e se questo è legato a una nuova versione di ubuntu, upstart, o bash. Se qualcuno può spiegare, si prega di carillon in

Ho incluso il mio script di lavoro completa per tutti coloro che solo in cerca di una risposta.

# /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 
+1

Si prega di inviare un PR in modo che possiamo ottenere questo risolto upstream! –

+1

Vorrei utilizzare direttamente il supporto ENV di Upstart: http://upstart.ubuntu.com/cookbook/#env env HOME =/home/deploy –

+0

Vorrei poter risalire .bashrc dallo script Upstart. È incredibilmente fastidioso dover mettere env vars in due punti durante il provisioning delle app. – odigity

3

Il file predefinito .bashrc su Ubuntu 14.04 ha un paio di linee di tornare subito se la shell è in esecuzione in modalità non interattiva. Quando rimuovi quelle linee dal tuo bascrc allora source funzionerà come previsto in upstart.

~/.bashrc (linee da rimuovere)

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

Sono in esecuzione 14.04.4 e la riga che ho commentato dal file .bashrc era '[-z" $ PS1 "] && return'. Questo mi ha permesso di creare semplicemente il file .bashrc nello script di upstart. Grazie per il consiglio! –

0

soluzione di Josh non ha funzionato per me su Ubuntu 14.04 utilizzando rbenv. Ciò tuttavia ha funzionato:

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 
Problemi correlati