A 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 do the work for you and I must say - it works just great.
There are some caveats worth mentioning tho:
WantedBy = multi-user.targetdoesn’t work on ubuntu for user systemd services - you will want to useWantedBy = default.targetinstead.You will need to enable linger with
loginctl enable-lingerfor your particular user(s) that are running the app on your production system.If you encounter quirks regarding unicorn hot reloading try to set
WorkingDirectoryto current directory in your service declaration.When using
rvm1-capistrano3you can invokervm1:alias:createto 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).Make sure
~/.config/systemd/userdirectory exists on the first deploy - this probably should we incorporated incapistrano-systemd-multiserviceitself.