Skip to content

Instantly share code, notes, and snippets.

@errordeveloper
Last active February 9, 2022 09:21
Show Gist options
  • Select an option

  • Save errordeveloper/4329034 to your computer and use it in GitHub Desktop.

Select an option

Save errordeveloper/4329034 to your computer and use it in GitHub Desktop.

Revisions

  1. errordeveloper revised this gist Jan 21, 2013. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion Unicorn_and_Upstart.md
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ This presumes you are not using RVM, so no voodoo dances.
    start on virtual-filesystems
    stop on runlevel [06]

    env PATH=/opt/ruby/shims:/opt/ruby/rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    env PATH=/opt/ruby/shims:/opt/ruby/rbenv/bin:/usr/local/bin:/usr/bin:/bin

    env RAILS_ENV=production

    @@ -47,6 +47,8 @@ Please also note that it can be used for roll-back just as well.

    console log

    env PATH=/opt/ruby/shims:/opt/ruby/rbenv/bin:/usr/local/bin:/usr/bin:/bin

    chdir /opt/my_app/

    script
  2. errordeveloper revised this gist Jan 21, 2013. 2 changed files with 58 additions and 18 deletions.
    58 changes: 58 additions & 0 deletions Unicorn_and_Upstart.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    # Using Unicorn with Upstart

    ***This configuration works with Upstart on Ubuntu 12.04 LTS***

    The reason why it needs to be done this way (i.e. with the `pre-start` and `post-stop` stanzas), is because Upstart
    is unable to track whever Unicorn master process re-execs itself on hot deploys. One can use it without hot-deploys
    and run Unicorn in foreground also, it then only needs one exec stanza.

    This presumes you are not using RVM, so no voodoo dances.

    #/etc/init/my-app.conf
    description "My App"
    author "Ilya Dmitrichenko <errordeveloper@gmail.com>"

    start on virtual-filesystems
    stop on runlevel [06]

    env PATH=/opt/ruby/shims:/opt/ruby/rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

    env RAILS_ENV=production

    setuid nobody
    setgid nobody

    chdir /opt/my_app/

    pre-start exec ./bin/unicorn_rails -D -c /opt/my_app/config/unicorn.rb --env production

    post-stop exec kill `cat /opt/my_app/run/unicorn.pid`


    The next example allows one to run a very descriptive command
    from their deploy script:

    initctl emit my-app-deploy TAG=v1.2.3`.

    It demonstrates a very appropriate use of Upstart's events.
    Please also note that it can be used for roll-back just as well.

    #/etc/init/my-app-deploy-task.conf
    description "Upgade My App!"
    author "Ilya Dmitrichenko <errordeveloper@gmail.com>"

    on my-app-deploy

    task

    console log

    chdir /opt/my_app/

    script
    git fetch --quiet --all --tags origin
    git checkout --quiet --force --detach $TAG
    bundle --quiet install
    kill -USR2 `cat ./run/unicorn.pid`
    end script

    18 changes: 0 additions & 18 deletions my_app.conf
    Original file line number Diff line number Diff line change
    @@ -1,18 +0,0 @@
    description "My App"
    author "Ilya Dmitrichenko"

    start on virtual-filesystems
    stop on runlevel [06]

    env PATH=/etc/rbenv/shims:/usr/local/rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

    env RAILS_ENV=production

    setuid rails
    setgid rails

    chdir /opt/my_app/current

    pre-start exec bundle exec unicorn_rails -D -c /opt/my_app/shared/config/unicorn.rb --env production

    post-stop exec kill `cat /opt/my_app/shared/pids/unicorn.pid`
  3. errordeveloper created this gist Dec 18, 2012.
    18 changes: 18 additions & 0 deletions my_app.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    description "My App"
    author "Ilya Dmitrichenko"

    start on virtual-filesystems
    stop on runlevel [06]

    env PATH=/etc/rbenv/shims:/usr/local/rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

    env RAILS_ENV=production

    setuid rails
    setgid rails

    chdir /opt/my_app/current

    pre-start exec bundle exec unicorn_rails -D -c /opt/my_app/shared/config/unicorn.rb --env production

    post-stop exec kill `cat /opt/my_app/shared/pids/unicorn.pid`