Nek0's Blog

Daemonize a Yesod application

Posted on by nek0 in english, meta, programming

If you want to create a systemd service file, look here

As you might know I have written my own commenting service, which up until recently I had to start manually in a screen session. Then I decided to write my own init-script.

I have to admit, that I am no experienced sysadmin or something like that, but just a random guy with a strange love (or addiction) to computers. So this is my first time doing this.

For managing the starting and stopping of the service I chose to use the start-stop-daemon shipped with the system on my server. Additionally I used the skeleton file for init-scripts, which you can find in /etc/init.d/skeleton.

After consulting the manpage of start-stop-daemon I came up with the following command for starting the commenting service:

What this actually means: The first option ist pretty self explanatory. -b starts the service in the background. -u and --chuid ensure, that the service runs as a user, not as root. I chose my own user here, but you can also use nobody if you like. The name of the service is specified by --name. -d specifies the working directory of the service you want to start and finally --exec is the path to the executable, in this case relative to the working directory. Everything after the final double-dashes are arguments passed to the executable itself.

for stopping the whole thing I use the following command:

This is even simpler than the above and is really self explanatory after all the information you got above.

the whole init-script looks like this:

I hope this is helpful for others. If something is unclear, you can always leave a comment now ^^

Donate using Liberapay

If you see this, something is wrong