Search code examples
ruby-on-railsrubyweb-deploymentwebfaction

Why won't Huginn agents act on Webfaction?


I could spool up a VPS or deploy to a PaaS, but I'm determined to get Huginn working on my Webfaction account because I'm pretty sure it's possible and I just don't get rails deployments.

After hours of hacking away, I ended up with a running app whose Agents do nothing. I can't manage to run foreman start, the magical command that should solve the problem, so I'm not sure what else to do.

Background jobs that never get executed.

Choosing 'Run event propagation' confirms a queue of 0 events on 0 agents. 'Working' is always 'no'.]

How I got here

I'm used to PHP and these deployments are foreign to me, so I'm certain the problem's between the chair and the keyboard...

  1. Created a new Webfaction Application called huginn with Rails 4.1.8 (nginx 1.6.2/Passenger 4.0.53/Ruby 2.1.2).
  2. Cloned huginn into its own folder next to the hello_world example app that Webfaction initializes. (~/webapps/huginn/huginn/)
  3. Edited ~/webapps/nginx/conf/nginx.conf (which came from Webfaction's init script) to point to my cloned huginn folder instead of hello_world. Changed GEM_HOME to /home/foo/webapps/huginn/huginn/gems instead of /home/foo/webapps/huginn/gems, root to /home/foo/webapps/huginn/huginn/public, and rails_env to production.
  4. Edited ~/webapps/huginn/bin/start to adjust paths (see below).
  5. Copied and configured Huginn's .env properly, pointing to a fresh MySQL database with valid credentials. Added a randomly-generated APP_SECRET_TOKEN, set host name and email configuration.
  6. Added app bin, path, and gems to PATH using Webfaction's instructions.
  7. From ~/webapps/huginn/huginn, ran gem2.1 install bundle, ruby2.1 bin/bundle, ruby2.1 bin/bundle exec rake db:migrate, ruby2.1 bin/bundle exec rake db:seed and all goes well; dependencies installed to huginn's directories, database populated, etc.
  8. Ran ruby2.1 bin/bundle exec foreman start and failed:

16:50:03 web.1 | started with pid 7115
16:50:03 jobs.1 | started with pid 7116
16:50:06 jobs.1 | /home/foo/webapps/huginn/huginn/gems/gems/spring-1.1.3/lib/spring/server.rb:22:in `initialize': Permission denied @ rb_sysopen - /tmp/spring/e89e6bd5b6863aeed0fbb5c861b1fc2d.pid (Errno::EACCES)

  1. Go back and run ~/webapps/huginn/bin/stop, ~/webapps/huginn/bin/start, and the app miraculously starts working in my browser. Except for the Agents, which do nothing on schedule or an attempt to manually run them.

I suspect that I'm missing something when it comes to environment variables and ruby versions. Various ruby versions are available, but ruby --version outputs ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]. Even I figured out that there are symlinks to different versions, so ruby2.1 --version gets me ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]. My guess is that the app's using Ruby 1.8.7, and I ran with this trying to install rvm to select a different ruby version—I didn't make it through rvm install X.X.X because I'm not a sudoer and libyaml-devel couldn't be installed.

I was briefly excited to learn that I could run ruby2.1 bin/rails s --port=22766 --environment=production from the deployed app directory and have the app once again running in the browser—but with the exact same issue of non-responsive agents.

It seems like I'm really close, but that I'm missing something that's consistently leaving Huginn's agents crippled. What am I missing?


nginx.conf

env               GEM_HOME=/home/foo/webapps/huginn/huginn/gems;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    access_log  /home/foo/logs/user/access_huginn.log  combined;
    error_log   /home/foo/logs/user/error_huginn.log   crit;

    include         mime.types;
    passenger_root  /home/foo/webapps/huginn/gems/gems/passenger-4.0.53;
    passenger_ruby  /home/foo/webapps/huginn/bin/ruby;
    sendfile        on;

    passenger_max_instances_per_app  1;
    rails_spawn_method               conservative;
    passenger_max_pool_size 2;

    server {
        listen             22766;
        passenger_enabled  on;
        root               /home/foo/webapps/huginn/huginn/public;
        server_name        localhost;
        rails_env          production;
    }
}

~/webapps/huginn/bin/start

#!/bin/bash

PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/foo/bin RUBYLIB=/home/foo/webapps/huginn/huginn/lib:$RUBYLIB TMPDIR=/home/foo/webapps/huginn/tmp PASSENGER_TMPDIR=/home/foo/webapps/huginn/tmp GEM_HOME=/home/foo/webapps/huginn/huginn/gems /home/foo/webapps/huginn/nginx/sbin/nginx -p /home/foo/webapps/huginn/nginx/

Solution

  • Thanks to help from John at Webfaction, it boiled down to setting a custom temp directory that could be written to with my account...

    mkdir -p $HOME/tmp
    export TEMP=$HOME/tmp
    

    Sure enough, running ruby2.1 bin/bundle exec foreman start worked just fine and the Agents sprang to life.

    Then I promptly hit the wall of my 512MB memory limit, so it's on to other issues.