SystemD for your Apps

I have been experimenting with I have been experimenting with 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:

Description=hello_phoenix Service

Environment=MIX_ENV=prod PORT=4000
ExecStart=/var/www/hello_phoenix/rel/hello_phoenix/bin/hello_phoenix start
ExecStop=/var/www/hello_phoenix/rel/hello_phoenix/bin/hello_phoenix stop


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, was very helpful to solving this problem.