Skip to content

Commit

Permalink
Install as a service via systemd (Docker cannot be used).
Browse files Browse the repository at this point in the history
  • Loading branch information
bzamecnik committed Oct 22, 2018
1 parent e6a70f8 commit a66dda5
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 26 deletions.
30 changes: 30 additions & 0 deletions DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Installation and running via Docker

<dev>For easier deployment of the agent apps we can use Docker.</del>

> `psutils` cannot see process details (user, creation time, command) on the host
OS - by definition os container this is separated. This is a design fault of the
dockerized solution and I'm not sure if it can work at all.
See https://github.com/rossumai/nvgpu/issues/2.

It needs [nvidia-docker](https://github.com/NVIDIA/nvidia-docker) installed.

```bash
# build the image
docker build -t nvgpu .

# run CLI
nvidia-docker run --rm nvgpu nvl

# run agent
nvidia-docker run --rm -p 1080:80 nvgpu

# run the master with agents specified in ~/nvgpu_master.cfg
nvidia-docker run --rm -p 1080:80 -v $(pwd)/nvgpu_master.cfg:/etc/nvgpu.cfg nvgpu

open http://localhost:1080
```

You can set the containers for automatic startup with `--restart always` option.

Note: Docker containers have some hash as hostname (it's not the host machine hostname).
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ docker_build:

docker_run_nvl:
nvidia-docker run --rm nvgpu nvl

docker_run_agent:
nvidia-docker run --rm -p 1080:80 nvgpu

docker_run_master:
nvidia-docker run --rm -p 1080:80 -v $(pwd)/nvgpu_master.cfg:/etc/nvgpu.cfg nvgpu
#
#docker_run_agent:
# nvidia-docker run --rm -p 1080:80 nvgpu
#
#docker_run_master:
# nvidia-docker run --rm -p 1080:80 -v $(pwd)/nvgpu_master.cfg:/etc/nvgpu.cfg nvgpu
71 changes: 51 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,23 @@ status in a web application.

## Installing

For a user:

```bash
pip install -U nvgpu
```
pip install nvgpu

or to the system:

```bash
sudo -H pip install -U nvgpu
```

## Usage examples

Command-line interface:

```
```bash
# grab all available GPUs
CUDA_VISIBLE_DEVICES=$(nvgpu available)

Expand Down Expand Up @@ -60,7 +68,7 @@ $ nvl

Python API:

```
```python
import nvgpu

nvgpu.available_gpus()
Expand Down Expand Up @@ -97,7 +105,7 @@ Agents can also display their status by default.

### Agent

```
```bash
FLASK_APP=nvgpu.webapp flask run --host 0.0.0.0 --port 1080
```

Expand All @@ -118,37 +126,60 @@ AGENTS = [
]
```

```
```bash
NVGPU_CLUSTER_CFG=/path/to/nvgpu_master.cfg FLASK_APP=nvgpu.webapp flask run --host 0.0.0.0 --port 1080
```

Open the master in the web browser: http://node01:1080.

## Installation and running via Docker
## Installing as a service

For easier deployment of the agent apps we can use Docker.

It needs [nvidia-docker](https://github.com/NVIDIA/nvidia-docker) installed.
On Ubuntu with `systemd` we can install the agents/master as as service to be
ran automatically on system start.

```bash
# build the image
docker build -t nvgpu .
# create an unprivileged system user
sudo useradd -r nvgpu
```

# run CLI
nvidia-docker run --rm nvgpu nvl
Copy [nvgpu-agent.service](nvgpu-agent.service) to:

# run agent
nvidia-docker run --rm -p 1080:80 nvgpu
```bash
sudo vi /etc/systemd/system/nvgpu-agent.service
```

# run the master with agents specified in ~/nvgpu_master.cfg
nvidia-docker run --rm -p 1080:80 -v $(pwd)/nvgpu_master.cfg:/etc/nvgpu.cfg nvgpu
Set agents to the configuration file for the master:

open http://localhost:1080
```bash
sudo vi /etc/nvgpu.conf
```

You can set the containers for automatic startup with `--restart always` option.
```python
AGENTS = [
# direct access without using HTTP
'self',
'http://node01:1080',
'http://node02:1080',
'http://node03:1080',
'http://node04:1080',
]
```

Note: Docker containers have some hash as hostname (it's not the host machine hostname).
Set up and start the service:

```bash
# enable for automatic startup at boot
sudo systemctl enable nvgpu-agent.service
# start
sudo systemctl start nvgpu-agent.service
# check the status
sudo systemctl status nvgpu-agent.service
```

```bash
# check the service
open http://localhost:1080
```

## Author

Expand Down
15 changes: 15 additions & 0 deletions nvgpu-agent.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=NVGPU agent

[Service]
User=nvgpu
Group=nvgpu
Environment=NVGPU_CLUSTER_CFG=/etc/nvgpu.conf
Environment=FLASK_APP=nvgpu.webapp
Environment=FLASK_HOST=0.0.0.0
Environment=FLASK_PORT=1080
ExecStart=/bin/bash -c "/usr/local/bin/flask run --host $FLASK_HOST --port $FLASK_PORT"
Restart=always

[Install]
WantedBy=multi-user.target

0 comments on commit a66dda5

Please sign in to comment.