alxvallejo

alxvallejo

Just getting up to speed on Elixir 1.9 deployments. I’m super excited about not relying on Distillery and eDeliver and even Docker containers (since I’m currently just tackling a smaller personal project), but I’m still getting caught up with how to properly do a release that runs in the background, via systemd.

I added GitHub - cogini/mix_systemd: Library of mix tasks to generate a systemd unit file for an Elixir project · GitHub to my deps and generated my systmd unit file and placed it in /etc/systemd/system and did some tests, but can’t get my app to show up at mysite:4000. Keep in mind, I originally just tested the build executable and was able to successfully see my app at that URL so I know the problem is somewhere with how I’m doing my systemd.

Here’s a copy of my systemd unit file:

[Unit]
Description=dayoff service
After=local-fs.target network.target

[Service]
Type=simple
User=deploy
Group=deploy
WorkingDirectory=/home/deploy/build/dayoff_1.9/_build/prod/rel/dayoff
ExecStart=/home/deploy/build/dayoff_1.9/_build/prod/rel/dayoff/bin/dayoff start
ExecStop=/home/deploy/build/dayoff_1.9/_build/prod/rel/dayoff/bin/dayoff stop
Environment=LANG=en_US.utf8
Environment=MIX_ENV=prod

Environment=PORT=4000
LimitNOFILE=65535
UMask=0027
SyslogIdentifier=dayoff
Restart=always

[Install]
WantedBy=multi-user.target

If i run a status check on the systemd service I see that it is active, however it seems to be starting and stopping every couple seconds.

● dayoff.service - dayoff service
   Loaded: loaded (/etc/systemd/system/dayoff.service; disabled;
   Active: active (running) since Sun 2020-02-23 10:24:49 EST; 7
  Process: 20886 ExecStop=/home/deploy/build/dayoff_1.9/_build/p
 Main PID: 20944 (beam.smp)
    Tasks: 5
   Memory: 6.4M
      CPU: 48ms
   CGroup: /system.slice/dayoff.service
           ├─20944 /home/deploy/build/dayoff_1.9/_build/prod/rel
           └─20986 erl_child_setup 65535

Feb 23 10:24:49 seojeek systemd[1]: dayoff.service: Service hold
Feb 23 10:24:49 seojeek systemd[1]: Stopped dayoff service.
Feb 23 10:24:49 seojeek systemd[1]: Started dayoff service.

Another area of potential confusion is where exactly I place my env vars. I was able to build my release successfully using the vars stored on the server in ~/.profile which I think seems to be a fine solution.

However, in my prod.exs I have some config vars for mix_systemd:

config :mix_systemd,
  app_user: "deploy",
  app_group: "deploy",
  base_dir: "/home/deploy/build/dayoff_1.9/_build/prod/rel",
  current_dir: "/home/deploy/build/dayoff_1.9/_build/prod/rel",
  env_vars: [
    "PORT=4000",
  ]

So I’m not sure if I should replace my ~/.profile and place them in my systemd config?

So yeah, any help is appreciated. Again, if I take the ExecStart command from my systemd file it runs so I just want to set it and forget it but can’t get it to stay on.

Thanks.

Showing Posts 1 to 2

hauleth

hauleth

While I like the idea of that tool I highly suggest You to learn how to write your own unit files. It is not that hard to achieve similar level to the one that is presented in Your snipped, but in the long run it gives you more flexibility and insights how to work with systemd.

Are you sure that you are listening on proper interface? Because if you listen on loopback address, then it will be natural that you cannot connect to that service.

Active service do not mean healthy. It just mean that the application started and that is it.

Such behaviour mean that the application cannot start in reality, you need to check logs for informations about failures in your application, as it seems that the application starts (from the viewpoint of systemd) then internally it cannot start some process, so it restarts until you rect supervisor restart limit, then it shuts down init process and whole process starts again. If you want better insights what is happening in your application you can check out my systemd library and example project where I use watchdog to monitor real state of the application.

alxvallejo

alxvallejo OP

I’m not sure what you mean here. If I run my app without systemd, it works fine on port 4000 so I’m assuming things are setup fine for that port.

I’ll try out your module. But here’s a question for you. Why am I relying on watchdog and not journalctl as seen here: GitHub - cogini/mix-deploy-example: Example Elixir app which uses mix_systemd and mix_deploy to deploy · GitHub ?

Also, here’s an interesting comment hinting that maybe I shouldn’t rely on watchdog? https://unix.stackexchange.com/a/313772/56953

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews