Few weeks ago I was upgrading legacy infrastructure for small sized project and decided to go with systemd for service management as I had quite good experience with it while tinkering with my toy apps written in Crystal.

If you want to use systemd for rails/ruby project - there is a great news everyone! capistrano-systemd-multiservice will basically do the work for you and it I must say - it works just great.

There are some caveats worth mentioning tho:

  1. WantedBy = multi-user.target doesn’t work on ubuntu for user systemd services - you will want to use WantedBy = default.target instead.

  2. You will need to enable linger with loginctl enable-linger for your particular user(s) that are running the app on your production system.

  3. If you encounter quirks regarding unicorn hot reloading try to set WorkingDirectory to current directory in your service declaration.

  4. When using rvm1-capistrano3 you can invoke rvm1:alias:create to generate nice aliases under ~/.rvm/wrappers/<application> - this is very handy in services declaration as you don’t have to reference ruby version directly (less hassle during ruby upgrade - you can simply invoke alias creation on every deploy).

  5. Make sure ~/.config/systemd/user directory exists on first deploy - this actually probably should we incorporated in capistrano-systemd-multiservice itself.