Skip to content

Commit

Permalink
Supervisord files for dal (#2341)
Browse files Browse the repository at this point in the history
* feat: supervisord files for dal

* feat: add task

* feat: add example env file

* fix: update based on feedbacks
  • Loading branch information
nick-bisonai authored Dec 14, 2024
1 parent 99409d4 commit 1f8c521
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
13 changes: 13 additions & 0 deletions node/cmd/dal/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DAL_API_PORT=
KAIA_PROVIDER_URL=
KAIA_WEBSOCKET_URL=
SUBMISSION_PROXY_CONTRACT=
REDIS_HOST=
REDIS_PORT=
SUB_REDIS_HOST=
SUB_REDIS_PORT=
CHAIN=
POST_TO_LOGSCRIBE=
LOGSCRIBE_ENDPOINT=
DATABASE_URL=
API_KEY=
4 changes: 4 additions & 0 deletions node/taskfiles/taskfile.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ tasks:
dotenv: [".env"]
cmds:
- go run ./cmd/dal/main.go
dal-build:
cmds:
- mkdir -p ~/bin
- go build -v -o ~/bin/dal ./cmd/dal
reporter:
dotenv: [".env"]
cmds:
Expand Down
94 changes: 94 additions & 0 deletions supervisor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Supervisor

## Knowledge base

- All binaries are stored in `~/bin` directory (directory is automatically created during build step)
- All environment files are stored in `~/bin` directory
- All logs are stores in `~/log` directory (directory must be manually created)

## Prerequisities

All prerequisities are supposed to be done only once when setting up the VM.

### Install gcc

```shell
sudo apt install gcc
```

### Install Go (go1.21.5)

```shell
cd ~
mkdir go
wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz

sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz
```

Set path to go binary

```shell
echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc
```

### Install supervisor

Ubuntu

```shell
sudo apt install supervisor
```

MacOS

```shell
brew install supervisor
```

### Create log directory

```shell
mkdir ~/log
```

## First-time deployment

1. Fetch git tag representing the version of the service you are going to deploy.

```shell
git fetch --all --tags --prune
git checkout tags/<tag_name>
```

2. Build binary of the service to be deployed (e.g. call `task local:dal-build` to create `dal` in `~/bin/`)
3. Create symlink from `supervisor/*.conf` file to `/etc/supervisor/conf.d/*.conf` (MacOS uses `/opt/homebrew/etc/supervisor.d/*.conf`)
4. Create symlink to (or copy) `.env.*` file (`.env` file is in format `.env.service_name`) to `~/bin`
5. Launch service through supervisor

```shell
supervisorctl
reread
update
```

## Update

1. Fetch git tag representing the version of the service you are going to deploy.

```shell
git fetch --all --tags --prune
git checkout tags/<tag_name>
```

2. Build binary of the service to be deployed (e.g. call `task local:dal-build` to create `dal` in `~/bin/`)
3. Update `*.conf` if necessary
4. Update `.env.*` if necessary
5. Launch service through supervisor

```shell
supervisorctl
reread
update
```
7 changes: 7 additions & 0 deletions supervisor/dal.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[program:dal]
command=%(HOME)s/bin/dal -env %(HOME)s/bin/.env.dal
directory=%(HOME)s/bin
autostart=true
autorestart=true
stderr_logfile=%(HOME)s/log/dal.err.log
stdout_logfile=%(HOME)s/log/dal.out.log

0 comments on commit 1f8c521

Please sign in to comment.