Search code examples
ruby-on-railsubunturvmupstart

ruby won't start or stop with upstart


The wrapper script works standalone but I can't stop or start the process via upstart. The ubuntu stop and start hangs and I have expect daemon on for pid tracking since it has it's own pid file.

/etc/init/tracks.conf:

start on runlevel [2345] and started networking
stop on runlevel [!2345] or stopped networking

author "Root <root@localhost>"

description "tracks wrapper for upstart"

expect daemon

exec sudo -u ubuntu /usr/local/bin/tracks >> /home/ubuntu/tracks/log/upstart.log 2>&1

respawn
respawn limit 1 10

The /usr/local/bin/tracks wrapper script:

#!/bin/bash
source /etc/profile.d/rvm.sh
export rvmsudo_secure_path=1
cd /home/ubuntu/tracks && /usr/local/rvm/bin/rvmsudo bundle exec rails server -e production -p 80 -d

Solution

  • This fixed it in /etc/init/tracks.conf

    start on runlevel [2345] and started networking
    stop on runlevel [!2345] or stopped networking
    
    author "Root <root@localhost>"
    
    description "tracks wrapper for upstart"
    
    chdir /home/ubuntu/tracks
    
    pre-start script
        exec sudo -u ubuntu "/usr/local/bin/tracks"
    end script
    
    post-stop exec kill -9 `cat /home/ubuntu/tracks/tmp/pids/server.pid`