POA Forum

How to autostart?

I have been trying to get the blockscout to start on boot with systemd and init scripts both which failed.

I cant even run the command in background because it closes right away.

I cant find documentation how to run a elixir / mix command on startup with a systemd service file.

Does anyone know how to run mix phx.server on boot?

Thanks :slight_smile:

Take a look to the Bash script, which we use to run Blockscout as a service in Terraform - Ansible setup https://github.com/poanetwork/blockscout-terraform/blob/2a9879c9cbdcaf7bc2ba088011739a5fd71835b8/roles/main_infra/files/libexec/init.sh#L124-L143. Hope it will help you.

2 Likes

That is exactly what I was looking for. Thank you so much!

So I tried and I can’t seem to get it to work. Here is my modified service file:

[Unit]
Description=NRGExplorer
After=network.target
[Service]
Type=simple
StandardOutput=journal
StandardError=journal
SyslogIdentifier=nrgexplorer
User=explorers
WorkingDirectory=/home/explorers/explorers/nrg/
ExecStart=/usr/bin/mix phx.server
Environment="MIX_ENV=prod"
EnvironmentFile=/etc/environment
KillMode=process
TimeoutStopSec=30
Restart=on-failure
RestartSec=5
RemainAfterExit=no
[Install]
WantedBy=multi-user.target

I am not sure why it wont start. My environment variables from testing were copied into /etc/environment

When I run service nrg-explorer start I get no output and the results of ps -axu | grep mix is empty :confused:

journalctl -xe shows the following

Apr 29 03:25:47 nrg.easyx.info nrgexplorer[30863]: /usr/bin/env: ‘elixir’: No such file or directory
Apr 29 03:25:47 nrg.easyx.info systemd[1]: nrgexplorer.service: Main process exited, code=exited, status=127/n/a
Apr 29 03:25:47 nrg.easyx.info systemd[1]: nrgexplorer.service: Failed with result 'exit-code'.

[UPDATE]
I have got a process now showing, but the explorer is not loading in the browser and the port is not listening :confused:

I have a feeling it is compiling it all over again because I found this in journalctl:
nrgexplorer[15857]: Compiling lib/explorer/chain/cache/accounts.ex (it's taking more than 15s)

[UPDATE] turns out it was recompiling and it finished. It is loading on a different port, but loading none the less :slight_smile:

1 Like