# Production deployment of Genie app with systemd

**URL:** <https://discourse.julialang.org/t/production-deployment-of-genie-app-with-systemd/72281>\
**Category:** Web Stack\
**Tags:** genie, deployment\
**Created:** [November 30, 2021, 9:38am UTC](https://discourse.julialang.org/t/production-deployment-of-genie-app-with-systemd/72281 "2021-11-30T09:38:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulDebus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauldebus/32/31218_2.png) [@PaulDebus](https://discourse.julialang.org/u/PaulDebus)\
**Post date:** [November 30, 2021, 9:38am UTC](https://discourse.julialang.org/t/production-deployment-of-genie-app-with-systemd/72281/1 "2021-11-30T09:38:45Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![hhaensel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hhaensel/32/1207_2.png) [@hhaensel](https://discourse.julialang.org/u/hhaensel)\
**Post date:** [November 30, 2021, 11:25am UTC](https://discourse.julialang.org/t/production-deployment-of-genie-app-with-systemd/72281/2 "2021-11-30T11:25:39Z")

</div>

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

```julia
macro wait()
    :(wait(Condition()))
end

```

and included the following line in the `Dockerfile`

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

```

---

<div class="post-metadata">

**Author:** ![PaulDebus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauldebus/32/31218_2.png) [@PaulDebus](https://discourse.julialang.org/u/PaulDebus)\
**Post date:** [November 30, 2021, 11:59am UTC](https://discourse.julialang.org/t/production-deployment-of-genie-app-with-systemd/72281/3 "2021-11-30T11:59:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hhaensel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hhaensel/32/1207_2.png) [@hhaensel](https://discourse.julialang.org/u/hhaensel)\
**Post date:** [November 30, 2021, 12:36pm UTC](https://discourse.julialang.org/t/production-deployment-of-genie-app-with-systemd/72281/4 "2021-11-30T12:36:49Z")

</div>

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

```julia
cd(@ __DIR__ )
using Pkg
pkg"activate ."
pkg"instantiate"

```

later you can comment out the `pkg"instantiate"`

---

<div class="post-metadata">

**Author:** ![PaulDebus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauldebus/32/31218_2.png) [@PaulDebus](https://discourse.julialang.org/u/PaulDebus)\
**Post date:** [November 30, 2021, 12:39pm UTC](https://discourse.julialang.org/t/production-deployment-of-genie-app-with-systemd/72281/5 "2021-11-30T12:39:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PaulDebus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauldebus/32/31218_2.png) [@PaulDebus](https://discourse.julialang.org/u/PaulDebus)\
**Post date:** [November 30, 2021, 1:46pm UTC](https://discourse.julialang.org/t/production-deployment-of-genie-app-with-systemd/72281/6 "2021-11-30T13:46:26Z")

</div>

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:

```julia
[Unit]
Description=My unit

[Service]
Type=simple
User=username
WorkingDirectory=/home/username/path/to/code
ExecStart=julia startup.jl
Restart=on-failure
RestartSec=10
KillMode=mixed

[Install]
WantedBy=multi-user.target

```
