Giter VIP home page Giter VIP logo

upstart-unicorn's Introduction

Ubuntu Upstart & Ruby Unicorn

WARNING: Do not use in production! This is a proof of concept only.
Introduction

Ubuntu upstart is an event-based replacement for the init daemon, it handles starting and supervising Linux services. While originally developed for Ubuntu, it can be used on any other Linux distribution.

Ruby unicorn is a popular HTTP server for Rack applications that has its own system of process management.

Unfortunately upstart is incompatible with unicorn's master "phoenix" way of respawning to a new process upon receiving the SIGUSR2 signal.


This little demo is a proof of concept utilizing upstart's little known utility called upstart-socket-bridge. The U-S-B is similar to how xinetd works, it listens to a socket and allows a process to take over the file descriptor once a connection has been made. U-S-B is passing the file descriptor information via the environment variable UPSTART_FDS.

Ruby unicorn has its own little known feature, one that is actually used to respawn into a new master. Unicorn is passing the previous file descriptors to a new master process via the UPSTART_FD environment variable.

The idea in this project, especially the unicorn_wrapper.rb file, is forgoing the Unicorn launch of its first master, and allowing Upstart to become that master via U-S-B unix sockets.

While this is an interesting experiment, there are a lot of bugs involved and this process is not recommended for actual production use. YMMV.


To test this demo, you will need an Ubuntu system (tested on Ubuntu 12.04 Precise), and a Rails project configured to be served via unicorn using the unicorn_wrapper.rb file.

Setup:

  • place unicorn_wrapper.rb in your rails project
  • edit project location and place unicorn_upstart.conf as /etc/init/unicorn.conf
  • copy nginx configuration unicorn_nginx.conf to /etc/nginx/sites-enabled/default
  • restart nginx

Troubleshooting:

  • upstart log file shows as /var/log/uptart/unicorn.log and has useful information
  • install socat with sudo apt-get install socat and test connectivity using sudo socat stdin unix-client:/var/run/unicorn.sock
  • nginx is using www-data as its user by default, configured in /etc/nginx/nginx.conf which might not have permissions writing to the unicorn socket owned by root. change nginx user to root helps resolve this.

upstart-unicorn's People

Contributors

kesor avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.