Production deployment of Genie app with systemd

I am trying to deploy a website built with Genie to production behind a nginx reverse proxy. The documentation and most tutorials suggest using screen to keep the app running. I would however prefer using systemd, as it offers more possibilities for debugging, restarting, and such.

In different threads here in discourse, I found mentions of people using systemd, but no specifics on how - our initial attempts all failed badly. Does anyone have a working example of a systemd service for the use with Julia or Genie?

Thanks in advance for any hints!

Not sure whether this will help for your use case. For deploying a Genie-based Stipple-app I defined a macro

macro wait()

and included the following line in the Dockerfile

CMD julia --threads auto --project=. -e "include(\"myapp.jl\"); @wait"

Thanks for the reply!

The code works fine when started from terminal, so the screen approach recommended in the docs would do it and I suppose also Docker would work like this. I would prefer using systemd, however we have trouble running the code, as packages are not found when run with a service.

Have you only tried using Docker or did you try different things before that?

The code wait(Condition()) makes the system wait after all lines of the script have been evaluated. So in order to translate that for your use case you may want to appent @wait or wait(Condition()) at the end of your code script. Then you should be able to run julia myapp.jl as a service.
You should make sure that the service has access to your julia installation. The service will not necessarily share your user environment, so you should make a Project.toml which is stored in the same directory as your scrpt and prepend something like

using Pkg
pkg"activate ."

later you can comment out the pkg"instantiate"

Ah, thanks for those hints. I will look into that, maybe I can get it running!

Well that definitely helped me fix it. I had to adjust the unit file, include your snippet and the @wait code, but now it works.

Thank you so much!

If somebody (me) stumbles upon this in the future, here is the systemd unit for reference:

Description=My unit

ExecStart=julia startup.jl