diff --git a/Makefile b/Makefile index b3f17f6..11acf50 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,18 @@ build: mkdir -p bin env GOOS=linux GOARCH=${ARCH} go build -o bin/rcond-${ARCH} ./cmd/rcond/main.go +install: + sudo mkdir -p /etc/rcond + sudo mkdir -p /var/rcond + sudo cp config/rcond.yaml /etc/rcond/config.yaml + sudo cp bin/rcond-${ARCH} /usr/local/bin/rcond + sudo cp systemd/rcond.service /etc/systemd/system/rcond.service + sudo systemctl daemon-reload + sudo systemctl enable rcond + sudo systemctl start rcond + run: - bin/rcond-${ARCH} -config config.yaml + bin/rcond-${ARCH} -config config/rcond.yaml dev: RCOND_ADDR=127.0.0.1:8080 \ diff --git a/README.md b/README.md index abd8408..7a6616f 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,16 @@ A simple daemon and REST API to manage: - systemd - Linux operating system +## Installation + +In order to install `rcond`as a systemd service, you need to specify the target architecture and then run the build and install make targets. + +```sh +export ARCH=arm64 +make build +make install +``` + ## Build and Run ```bash @@ -20,6 +30,34 @@ make build make run ``` +## Develop + +```sh +make dev +``` + +## Configuration + +### File + +The default config file location is `/etc/rcond/config.yaml`. +It can be overwritten by environment variables and flags. +An full example configuration with comments can be found in `config/rcond.yaml` + +Example configuration: +```yaml +rcond: + addr: 0.0.0.0:8080 + api_token: 1234567890 +``` + +### Environment Variables + +| Environment Variable | Description | Default | +|----------------------|-----------------------------------------|---------------| +| RCOND_ADDR | Address to bind the HTTP server to. | 0.0.0.0:8080 | +| RCOND_API_TOKEN | API token to use for authentication. | N/A | + ## API The full API specification can be found in [api/rcond.yaml](api/rcond.yaml). @@ -51,27 +89,6 @@ All endpoints except `/health` require authentication via an API token passed in ### Request/Response Format All endpoints use JSON for request and response payloads. -## Configuration - -### File - -The default config file location is `/etc/rcond/config.yaml`. -It can be overwritten by environment variables and flags. - -Example configuration: -```yaml -rcond: - addr: 0.0.0.0:8080 - api_token: 1234567890 -``` - -### Environment Variables - -| Environment Variable | Description | Default | -|----------------------|-----------------------------------------|---------------| -| RCOND_ADDR | Address to bind the HTTP server to. | 0.0.0.0:8080 | -| RCOND_API_TOKEN | API token to use for authentication. | N/A | - ## Examples ### Setup an Access Point diff --git a/config.yaml b/config.yaml deleted file mode 100644 index 5627dea..0000000 --- a/config.yaml +++ /dev/null @@ -1,3 +0,0 @@ -rcond: - addr: 0.0.0.0:8080 - api_token: 1234567890 diff --git a/.env b/config/.env similarity index 100% rename from .env rename to config/.env diff --git a/config/rcond.yaml b/config/rcond.yaml new file mode 100644 index 0000000..1043e09 --- /dev/null +++ b/config/rcond.yaml @@ -0,0 +1,5 @@ +rcond: + # Address to bind the HTTP server to + addr: 0.0.0.0:8080 + # API token to use for authentication + api_token: 1234567890 diff --git a/install/rcond.service b/systemd/rcond.service similarity index 60% rename from install/rcond.service rename to systemd/rcond.service index f284444..f46c4b8 100644 --- a/install/rcond.service +++ b/systemd/rcond.service @@ -5,8 +5,8 @@ After=network.target [Service] Type=simple User=root -WorkingDirectory=/path/to/your/rcond -ExecStart=/path/to/your/rcond/bin/rcond-${ARCH} ${ADDR} +WorkingDirectory=/var/rcond +ExecStart=/usr/local/bin/rcond Restart=on-failure [Install]