How to autostart a Phoenix website on reboot?

I have two websites running off my Linux box. However if the power goes down, which unfortunately in my area it does a couple of times a month or so, the websites do not auto restart. I have to go into each website directory and mix phx.server.

What is the best way, currently, canonically, to “package” a website application so that it will restart automatically on reboot ? What do I need to do on the Elixir/Phoenix side, and typically, what do I do on the Linux side? Thanks.

1 Like

The typical way is to generate a mix release, and then start that up with your OS’s init system. If you are using Systemd, you would write a unit file in most likely /etc/systemd/system/<yoursite>.service, then start and enable it (which will make it start on boot).

2 Likes

To add on top of what @Nicd said, you can find further information on his proposed solution here: Elixir apps as systemd services - info & wiki

2 Likes