I have been experimenting with Phoenix Framework for building apps and I have been really impressed with it (stay on the lookout for future posts). One thing I wanted to do was deploy it to a box in production. I wanted the server to stay up and for it to startup when the server was rebooted. There was a few things that stumped me and I was very happy when I was able to work them all out. Here is my final configuration file:
The things that got me where User= and Environment=. Originally I was trying to use su and set the environment variables in the command. This is ignored. The other thing that also caused me all sorts of problems was that I needed to set RemainAfterExit=yes as the start script actually executes another script and I didnt want systemd to kill the server after it had just started it. Hopefully this helps someone that is in a similar situation or was interested in systemd.
This comprehensive guide on systemd, https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files was very helpful to solving this problem.