Sidekiq with environment variables and systemd

Normal setup

Running Sidekiq with systemd is easy, download the sidekiq.service file from Github and place it in /etc/systemd/system.

Start it with: sudo systemctl start sidekiq

Enable it to run at boot: sudo systemctl enable sidekiq

And stop it: sudo systemctl stop sidekiq

The only lines you have to change are:

 

With environment variables

But what if you have some environment variables that you want to load before starting Sidekiq? Keep in mind that there are many ways to do this, and this only how I do it.

I put the environment variables in a hidden file called ‘.env’ in the home directory of the user that runs the application. If this user is called deploy, the file would be /home/deploy/.env

In it are my environment variables with export in front of them:

These are loaded when you log in through ssh with source as the first line in .bashrc. It doesn’t have to be the first line but it has to be above the “if not running interactively don’t do anything” line.

But how do these env variables reach Sidekiq? We’ll simply start Sidekiq with bash in the Systemd service file. Change the ExecStart line in /etc/systemd/system/sidekiq.service and add /bin/bash -lc in front.

Bash will load the environment variables and then start Sidekiq.

Is Digital Ocean’s One-click app for Ruby on Rails any good?

Digital Ocean offers 2 types of droplets (servers):

  1. Droplets with a clean Linux install.
  2. Droplets with some application preinstalled: “One-click apps”

Let’s have a look at the One-click Rails installation they offer. I’ll describe what you get and what I like about, what I don’t like about it and I’ll give some tips on how to use it.

Welcome to One-click apps, what do they do? Do they do things? Let’s find out!”

Continue reading “Is Digital Ocean’s One-click app for Ruby on Rails any good?”

Simple downtime alerts for your Rails app in 5 minutes

How do you know your Rails app is still online? How do you know it’s not displaying some error? That’s what monitoring is for. If you look around you’ll find lots of solutions. Most of these solutions are overkill if you are just starting with Rails servers or if you only have a few applications.

What is important when choosing a monitoring tool?

Continue reading “Simple downtime alerts for your Rails app in 5 minutes”

Why you shouldn’t run two Rails apps on the same server

It sounds convenient right? Install a server once and every time you build an app you add it to the server. If you update something on the server it will be updated for all the apps at the same time. Which may save you time and money.

Is it hard to install multiple apps on the same server? No not at all. Will it save you time setting things up? Yes. Will it make you happy in the long run? No!

Continue reading “Why you shouldn’t run two Rails apps on the same server”