Question

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

Posted March 21, 2017 2.1k views
Ruby on RailsUbuntu 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?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

Did you get an answer???

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!

Submit an Answer