Ruby on Rails

To run apps based on the Ruby on Rails framework using Unit:

  1. Install Unit with a Ruby language module.

  2. Install Ruby on Rails and create or deploy your app. Here, we use Ruby on Rails’s basic template:

    console
    $ cd /path/to/ # Path where the application directory will be created; use a real path in your configuration 
    console
    $ rails new app # Arbitrary app name; becomes the application directory name 

    This creates the app’s directory tree at /path/to/app/; its public/ subdirectory contains the static files, while the entry point is /path/to/app/config.ru.

  3. Change ownership:

    Run the following command (as root) so Unit can access the application directory (If the application uses several directories, run the command for each one):

    console
    # chown -R unit:unit /path/to/app/ # User and group that Unit's router runs as by default 
    The unit:unit user-group pair is available only with official packages , Docker images, and some third-party repos. Otherwise, account names may differ; run the ps aux | grep unitd command to be sure.

    For further details, including permissions, see the security checklist.

  4. Next, prepare the Ruby on Rails configuration (use real values for share and working_directory):

    json
    {  "listeners": {  "*:80": {  "pass": "routes"  }  },  "routes": [  {  "action": {  "share": "/path/to/app/public$uri",  "share_comment": "Serves static files",  "fallback": {  "pass": "applications/rails"  }  }  }  ],  "applications": {  "rails": {  "type": "ruby",  "script": "config.ru",  "script_comment": "All requests are handled by a single script, relative to working_directory",  "working_directory": "/path/to/app/",  "working_directory_comment": "Path to the application directory, needed here for 'require_relative' directives; use a real path in your configuration"  }  } }
  5. Upload the updated configuration.

    Assuming the JSON above was added to config.json. Run the following command as root:

    console
    # curl -X PUT --data-binary @config.json --unix-socket \  /path/to/control.unit.sock \ # Path to Unit's control socket in your installation  http://localhost/config/ # Path to the config section in Unit's control API 
    The control socket path may vary; run unitd -h or see Startup and shutdown for details.

    After a successful update, your app should be available on the listener’s IP address and port:

    Ruby on Rails Basic Template App on Unit