Skip to content

ASIC Sentry - How to deploy manually?

[1] Copy from release directory prod/rel/asic_sentry to /opt/asic_sentry

$ cp _build/prod/rel/asic_sentry /opt -rf

[2] Directory structure of /opt/asic_sentry

➜ asic_sentry (master) ✔ tree -L 1 /opt/asic_sentry

/opt/asic_sentry
├── bin
├── erts-15.0
├── lib
└── releases

[3] Test run with script before working with systemd service.

export SECRET_KEY_BASE=Mc5oIum6N8aeNdjghwfJQYVE2OQncnqBkCCyaXdA1X/puugR99VvcSuvAqOoGYdW
export PORT=4001
export PHX_HOST=127.0.0.1
export DATABASE_FILE=/opt/asic_sentry_data/data.db
mkdir /opt/asic_sentry_data;

# Migrate sqlite database
/opt/asic_sentry/bin/migrate
...
00:29:39.840 [info] == Running 20250116173006 AsicSentry.Repo.Migrations.CreateAsicMiners.change/0 forward
00:29:39.843 [info] create table asic_miners
00:29:39.844 [info] == Migrated 20250116173006 in 0.0s
00:29:39.885 [info] == Running 20250118184800 AsicSentry.Repo.Migrations.CreateUniqueConstraintApiCodeColInAsicMinersTable.change/0 forward
00:29:39.885 [info] create index asic_miners_api_code_index
00:29:39.885 [info] == Migrated 20250118184800 in 0.0s
00:29:39.886 [info] == Running 20250118184801 AsicSentry.Repo.Migrations.CreateConfigs.change/0 forward
00:29:39.886 [info] create table configs
00:29:39.887 [info] create index configs_key_index
00:29:39.887 [info] == Migrated 20250118184801 in 0.0s


# Run server, go to http://127.0.0.1:4001
/opt/asic_sentry/bin/server
...
00:30:57.430 [info] [AsicMinerLogSender] Started
00:30:57.430 [info] [AsicSentry.Worker.AsicMinerSpecsSender] Started
00:30:57.430 [info] [Elixir.AsicSentry.Worker.AsicMinerSpecsStash] Started
00:30:57.444 [info] Running AsicSentryWeb.Endpoint with Bandit 1.6.5 at :::4001 (http)

[4] Create systemd service /etc/systemd/system/asic_sentry.service

[Unit]
Description=ASIC Sentry
After=network.target

[Service]
WorkingDirectory=/opt/asic_sentry
EnvironmentFile=/etc/asic_sentry/asic_sentry.env
ExecStart=/opt/asic_sentry/bin/server
ExecStop=/opt/asic_sentry/bin/mining_rig_monitor stop
User=nguyenvinhlinh
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

[5] Create environment file /etc/asic_sentry/asic_sentry.env

SECRET_KEY_BASE=
DATABASE_FILE=/opt/asic_sentry_data/data.db
PORT=4001
PHX_HOST=127.0.0.1

Regarding PHX_HOST, modify it to match domain/ip which web browser calling. if not, there will be an error.

[error] Could not check origin for Phoenix.Socket transport.
Origin of the request: http://192.168.1.9:4000
This happens when you are attempting a socket connection to
a different host than the one configured in your config/
files. For example, in development the host is configured
to "localhost" but you may be trying to access it from
"127.0.0.1". To fix this issue, you may either:
  1. update [url: [host: ...]] to your actual host in the
     config file for your current environment (recommended)
  2. pass the :check_origin option when configuring your
     endpoint or when configuring the transport in your
     UserSocket module, explicitly outlining which origins
     are allowed:
        check_origin: ["https://example.com",
                       "//another.com:888", "//other.com"]

and run systemctl daemon-reload

[6] Start systemd service named asic_sentry

systemctl enable --now asic_sentry

[7] To view log

journalctl -f -u asic_sentry.service