Can someone explain how to use the .unicorn.sh file on the one-click Rails 5/Ubuntu 16.04 install to export environment variables?

March 21, 2017 1.1k views
Ruby on Rails Ubuntu 16.04

I understand that it's supposed to run through systemd, and looking at /etc/systemd/system/unicorn.service, it should be triggered before running ngnix.service. But when I restart nginx or unicorn using systemctl as the rails user, none of the environment variables in the .unicorn.sh script are exported. What gives?

2 Answers

I'm looking for the same answer. Anyone?

  • Did you figure this out?

    • Yes. Thing is like this:
      If everything's correctly set (as it comes in the default state of the 1-click Droplet), unicorn.sh will be run when you do sudo systemctl start unicorn. When this happens, the environment variables you export in that script will be set and valid in the scope of that execution (this means the unicorn process). If you want to set others, for example to run bundle exec rails db:setup you can do it in the .bashrc file for the current user (e.g.: rails). By the way, doing that last thing is recommendable in my opinion, since adding RAILS_ENV=production after those kind of commands doesn't work at least for me.

      Hope this helps!

Have another answer? Share your knowledge.