Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add steps to create systemd services #63

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 34 additions & 20 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build
- name: Test
env:
GOOS: linux
GOARCH: amd64
Expand All @@ -22,39 +22,53 @@ jobs:
cd $PROJECT_PATH

go mod vendor

go test -race -coverprofile=coverage.txt -covermode=atomic -v -tags "static" $(go list ./... | grep -v /vendor/)

- name: Build amd64
env:
GOOS: linux
GOARCH: amd64
run: |
cd $PROJECT_PATH
go build -ldflags "-X main.goos=linux -X main.goarch=amd64" -o scrutiny-web-linux-amd64 -tags "static" webapp/backend/cmd/scrutiny/scrutiny.go
go build -ldflags "-X main.goos=linux -X main.goarch=amd64" -o scrutiny-collector-metrics-linux-amd64 -tags "static" collector/cmd/collector-metrics/collector-metrics.go

chmod +x scrutiny-web-linux-amd64
chmod +x scrutiny-collector-metrics-linux-amd64

- name: Build arm64
env:
GOOS: linux
GOARCH: arm64
run: |
cd $PROJECT_PATH
go build -ldflags "-X main.goos=linux -X main.goarch=arm64" -o scrutiny-web-linux-arm64 -tags "static" webapp/backend/cmd/scrutiny/scrutiny.go
go build -ldflags "-X main.goos=linux -X main.goarch=arm64" -o scrutiny-collector-metrics-linux-arm64 -tags "static" collector/cmd/collector-metrics/collector-metrics.go

chmod +x scrutiny-web-linux-arm64
chmod +x scrutiny-collector-metrics-linux-arm64

- name: Build windows
env:
GOOS: windows
GOARCH: amd64
run: |
cd $PROJECT_PATH
go build -ldflags "-X main.goos=windows -X main.goarch=amd64" -o scrutiny-web-windows-amd64.exe -tags "static" webapp/backend/cmd/scrutiny/scrutiny.go
go build -ldflags "-X main.goos=windows -X main.goarch=amd64" -o scrutiny-collector-metrics-windows-amd64.exe -tags "static" collector/cmd/collector-metrics/collector-metrics.go

- name: Archive
uses: actions/upload-artifact@v2
with:
name: binaries
name: binaries.zip
path: |
${{ env.PROJECT_PATH }}/scrutiny-web-linux-amd64
${{ env.PROJECT_PATH }}/scrutiny-collector-metrics-linux-amd64
${{ env.PROJECT_PATH }}/scrutiny-web-linux-arm64
${{ env.PROJECT_PATH }}/scrutiny-collector-metrics-linux-arm64
${{ env.PROJECT_PATH }}/scrutiny-web-windows-amd64.exe
${{ env.PROJECT_PATH }}/scrutiny-collector-metrics-windows-amd64.exe
- uses: codecov/codecov-action@v1
with:
file: ${{ env.PROJECT_PATH }}/coverage.txt
flags: unittests
fail_ci_if_error: true
build-docker:
name: Build Docker
runs-on: ubuntu-latest
container: docker:19.03.2
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build Docker
run: |
docker build -t analogj/scrutiny -f docker/Dockerfile .
docker save -o docker-analogj-scrutiny-latest.tar analogj/scrutiny:latest
- name: Archive Docker
uses: actions/upload-artifact@v2
with:
name: docker
path: docker-analogj-scrutiny-latest.tar
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ Scrutiny is a simple but focused application, with a couple of core features:

# Getting Started

## RAID/Virtual Drives

Scrutiny uses `smartctl --scan` to detect devices/drives.

- All RAID controllers supported by `smartctl` are automatically supported by Scrutiny.
- While some RAID controllers support passing through the underlying SMART data to `smartctl` others do not.
- In some cases `--scan` does not correctly detect the device type, returning [incomplete SMART data](https://github.com/AnalogJ/scrutiny/issues/45).
Scrutiny will eventually support overriding detected device type via the config file.
- If you use docker, you **must** pass though the RAID virtual disk to the container using `--device` (see below)
- This device may be in `/dev/*` or `/dev/bus/*`.
- If you're unsure, run `smartctl --scan` on your host, and pass all listed devices to the container.


## Docker

If you're using Docker, getting started is as simple as running the following command:
Expand All @@ -68,8 +81,8 @@ analogj/scrutiny

- `/run/udev` is necessary to provide the Scrutiny collector with access to your device metadata
- `--cap-add SYS_RAWIO` is necessary to allow `smartctl` permission to query your device SMART data
- NOTE: If you have NVMe drives, you must use `--cap-add SYS_ADMIN` instead. See issue [#26](https://github.com/AnalogJ/scrutiny/issues/26#issuecomment-696817130)
- `--device` entries are required to ensure that your hard disk devices are accessible within the container
- NOTE: If you have **NVMe** drives, you must add `--cap-add SYS_ADMIN` as well. See issue [#26](https://github.com/AnalogJ/scrutiny/issues/26#issuecomment-696817130)
- `--device` entries are required to ensure that your hard disk devices are accessible within the container.
- `analogj/scrutiny` is a omnibus image, containing both the webapp server (frontend & api) as well as the S.M.A.R.T metric collector. (see below)

### Hub/Spoke Deployment
Expand All @@ -94,6 +107,13 @@ docker run -it --rm \
analogj/scrutiny:collector
```

## Manual Installation (without-Docker)

While the easiest way to get started with [Scrutiny is using Docker](https://github.com/AnalogJ/scrutiny#docker),
it is possible to run it manually without much work. You can even mix and match, using Docker for one component and
a manual installation for the other.

See [docs/INSTALL_MANUAL.md](docs/INSTALL_MANUAL.md) for instructions.

## Usage

Expand Down
1 change: 0 additions & 1 deletion collector/pkg/detect/devices_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package detect

import (
"github.com/analogj/scrutiny/collector/pkg/models"
"github.com/jaypipes/ghw"
"strings"
)

Expand Down
166 changes: 146 additions & 20 deletions docs/INSTALL_MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ a manual installation for the other.

Scrutiny is made up of two components: a collector and a webapp/api. Here's how each component can be deployed manually.

> Note: the `/opt/scrutiny` directory is not hardcoded, you can use any directory name/path.

## Webapp/API

### Dependencies
Expand All @@ -19,9 +21,9 @@ which is included by most linux OS's already.
Now let's create a directory structure to contain the Scrutiny files & binary.

```
mkdir -p /etc/scrutiny/config
mkdir -p /etc/scrutiny/web
mkdir -p /etc/scrutiny/bin
mkdir -p /opt/scrutiny/config
mkdir -p /opt/scrutiny/web
mkdir -p /opt/scrutiny/bin
```

### Config file
Expand All @@ -30,19 +32,19 @@ While it is possible to run the webapp/api without a config file, the defaults a
and so will need to be overridden. So the first thing you'll need to do is create a config file that looks like the following:

```
# stored in /etc/scrutiny/config/scrutiny.yaml
# stored in /opt/scrutiny/config/scrutiny.yaml

version: 1

web:
database:
# The Scrutiny webapp will create a database for you, however the parent directory must exist.
location: /etc/scrutiny/config/scrutiny.db
location: /opt/scrutiny/config/scrutiny.db
src:
frontend:
# The path to the Scrutiny frontend files (js, css, images) must be specified.
# We'll populate it with files in the next section
path: /etc/scrutiny/web
path: /opt/scrutiny/web
```

> Note: for a full list of available configuration options, please check the [example.scrutiny.yaml](https://github.com/AnalogJ/scrutiny/blob/master/example.scrutiny.yaml) file.
Expand All @@ -52,31 +54,84 @@ web:
Next, we'll download the Scrutiny API binary and frontend files from the [latest Github release](https://github.com/analogj/scrutiny/releases).
The files you need to download are named:

- **scrutiny-web-linux-amd64** - save this file to `/etc/scrutiny/bin`
- **scrutiny-web-frontend.tar.gz** - save this file to `/etc/scrutiny/web`
- **scrutiny-web-linux-amd64** - save this file to `/opt/scrutiny/bin`
- **scrutiny-web-frontend.tar.gz** - save this file to `/opt/scrutiny/web`

### Prepare Scrutiny

Now that we have downloaded the required files, let's prepare the filesystem.

```
# Let's make sure the Scrutiny webapp is executable.
chmod +x /etc/scrutiny/bin/scrutiny-web-linux-amd64
chmod +x /opt/scrutiny/bin/scrutiny-web-linux-amd64

# Next, lets extract the frontend files.
cd /etc/scrutiny/web
cd /opt/scrutiny/web
tar xvzf scrutiny-web-frontend.tar.gz --strip-components 1 -C .

# Cleanup
rm -rf scrutiny-web-frontend.tar.gz
```

### Start Scrutiny Webapp
### Install Scrutiny systemd service

You may install Scrutiny as a systemd service:

Create user and group for the service:

```
groupadd -r scrutiny
useradd -m -d /opt/scrutiny -s /sbin/nologin -r -g scrutiny scrutiny
```

Change file permissions:

```
chown -R scrutiny\:scrutiny /opt/scrutiny
```

Create the service unit file:

```
cat > /etc/systemd/system/scrutiny.service <<EOF
[Unit]
Description=Scrutiny disk health monitor
After=network.target

[Service]
Type=idle
User=scrutiny
Group=scrutiny
ExecStart=/opt/scrutiny/bin/scrutiny-web-linux-amd64 start --config /opt/scrutiny/config/scrutiny.yaml
TimeoutStartSec=600
TimeoutStopSec=600

[Install]
WantedBy=multi-user.target
EOF
```

Finally, we start the Scrutiny webapp:
Enable and start the service:

```
/etc/scrutiny/bin/scrutiny-web-linux-amd64 start --config /etc/scrutiny/config/scrutiny.yaml
systemctl daemon-reload
systemctl enable scrutiny
systemctl start scrutiny
```

Check log for any issues:

```
journalctl -u scrutiny
```

### Start Scrutiny Webapp (non-systemd)

If you are not using the systemd service, you can start the Scrutiny webapp in the
foreground:

```
/opt/scrutiny/bin/scrutiny-web-linux-amd64 start --config /opt/scrutiny/config/scrutiny.yaml
```

The webapp listens for traffic on `http://0.0.0.0:8080` by default.
Expand Down Expand Up @@ -105,7 +160,7 @@ So you'll need to install the v7+ version using one of the following commands:
Now let's create a directory structure to contain the Scrutiny collector binary.

```
mkdir -p /etc/scrutiny/bin
mkdir -p /opt/scrutiny/bin
```


Expand All @@ -114,7 +169,7 @@ mkdir -p /etc/scrutiny/bin
Next, we'll download the Scrutiny collector binary from the [latest Github release](https://github.com/analogj/scrutiny/releases).
The file you need to download is named:

- **scrutiny-collector-metrics-linux-amd64** - save this file to `/etc/scrutiny/bin`
- **scrutiny-collector-metrics-linux-amd64** - save this file to `/opt/scrutiny/bin`


### Prepare Scrutiny
Expand All @@ -123,18 +178,89 @@ Now that we have downloaded the required files, let's prepare the filesystem.

```
# Let's make sure the Scrutiny collector is executable.
chmod +x /etc/scrutiny/bin/scrutiny-collector-metrics-linux-amd64
chmod +x /opt/scrutiny/bin/scrutiny-collector-metrics-linux-amd64
```

### Install Scrutiny Collector systemd service

If you are using systemd, you may configure collector as a systemd service and
create a timer to invoke it periodically:

```
sudo cat > /etc/systemd/system/scrutiny-collector.service <<EOF
[Unit]
Description=Scrutiny disk health data collector

[Service]
Type=idle
ExecStart=/opt/scrutiny/bin/scrutiny-collector-metrics-linux-amd64 run --api-endpoint "http://localhost:8080"
TimeoutStartSec=600
TimeoutStopSec=600
EOF
```

Configure collector systemd timer:

```
Comment on lines 189 to +204

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migt make sense to specify lang (use ```\sh) and then make it a long list with comments in there like

# Create this file
sudo cat file <EOF
...
EOF
# Create that
sudo cat file <EOF
...
EOF
# Enable timer
systemctl this
systemctl that

sudo cat > /etc/systemd/system/scrutiny-collector.timer <<EOF
[Unit]
Description=Scrutiny disk health data collector timer

[Timer]
OnCalendar=*:0/15
Unit=scrutiny-collector.service
Persistent=true

[Install]
WantedBy=timers.target
EOF
```

Enable timer:

```
systemctl daemon-reload
systemctl enable scrutiny-collector.timer
systemctl start scrutiny-collector.timer
Comment on lines +223 to +224

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could shorten with systemctl enable --now scutiny-collector.timer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added a type correction 🙂 systemctl enable --now scrutiny-collector.timer

```

Check timer:

```
systemctl is-active scrutiny-collector.timer
```

Should say `active`

Check the next scheduled run:

```
systemctl list-timers scrutiny*
```

Manually run the first data collection:

```
systemctl start scrutiny-collector.service
```

Check log for any issues:

```
journalctl -u scrutiny-collector.service
```

### Non-systemd configuration

### Start Scrutiny Collector, Populate Webapp
#### Start Scrutiny Collector, Populate Webapp

Next, we will manually trigger the collector, to populate the Scrutiny dashboard:

```
/etc/scrutiny/bin/scrutiny-collector-metrics-linux-amd64 run --api-endpoint "http://localhost:8080"
/opt/scrutiny/bin/scrutiny-collector-metrics-linux-amd64 run --api-endpoint "http://localhost:8080"
```

### Schedule Collector with Cron
#### Schedule Collector with Cron

Finally you need to schedule the collector to run periodically.
This may be different depending on your OS/environment, but it may look something like this:
Expand All @@ -144,5 +270,5 @@ This may be different depending on your OS/environment, but it may look somethin
crontab -e

# add a line for Scrutiny
*/15 * * * * /etc/scrutiny/bin/scrutiny-collector-metrics-linux-amd64 run --api-endpoint "http://localhost:8080"
*/15 * * * * /opt/scrutiny/bin/scrutiny-collector-metrics-linux-amd64 run --api-endpoint "http://localhost:8080"
```
Loading