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

docs: how to manage remote systems #547

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ce3b434
docs: how to use api
IronCore864 Dec 31, 2024
be84674
chore: refactor according to review
IronCore864 Jan 4, 2025
092702c
docs: how to manage remote systems draft
IronCore864 Jan 6, 2025
9246883
Merge remote-tracking branch 'origin/how-to-use-api' into docs-how-to…
IronCore864 Jan 6, 2025
593715a
chore: fix links
IronCore864 Jan 6, 2025
ea98b57
chore: refactor after merging changes from how to use api
IronCore864 Jan 6, 2025
bdfe190
chore: fix broken links
IronCore864 Jan 6, 2025
59279ea
chore: add links
IronCore864 Jan 6, 2025
f305d68
chore: refactor after review
IronCore864 Jan 7, 2025
c6f0746
chore: remove separating lines
IronCore864 Jan 9, 2025
766af89
chore: remove separating lines
IronCore864 Jan 9, 2025
7cf294a
chore: add a space to trigger another doc build
IronCore864 Jan 13, 2025
fda3f07
chore: and remove it
IronCore864 Jan 13, 2025
9c5ed09
Merge branch 'master' of github.com:IronCore864/pebble
IronCore864 Jan 20, 2025
478630d
Merge branch 'master' into how-to-use-api
IronCore864 Jan 20, 2025
3b6f385
chore: refactor after discussion
IronCore864 Jan 20, 2025
0e0ae4e
chore: refactor after discussion
IronCore864 Jan 20, 2025
6b1dc5b
Merge branch 'master' into docs-how-to-manage-remote-systems
IronCore864 Jan 20, 2025
14345af
chore: refactor after discussion
IronCore864 Jan 20, 2025
fa9fb33
chore: refactor according to review
IronCore864 Jan 21, 2025
720b793
chore: refactor according to review
IronCore864 Jan 21, 2025
dc34b65
chore: refactor according to review
IronCore864 Jan 21, 2025
7092a65
chore: refactor according to review
IronCore864 Jan 23, 2025
a587275
chore: refactor according to review
IronCore864 Jan 23, 2025
21b7984
Merge branch 'how-to-use-api' into docs-how-to-manage-remote-systems
IronCore864 Jan 23, 2025
c7ff165
Update docs/how-to/use-the-pebble-api.md
IronCore864 Jan 23, 2025
1a9679f
Merge branch 'how-to-use-api' into docs-how-to-manage-remote-systems
IronCore864 Jan 23, 2025
495f5e2
Merge branch 'master' into docs-how-to-manage-remote-systems
IronCore864 Jan 23, 2025
f22df75
Merge branch 'master' into docs-how-to-manage-remote-systems
IronCore864 Jan 23, 2025
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
24 changes: 24 additions & 0 deletions docs/how-to/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ Manage service dependencies <service-dependencies>
```


## Manage a remote system

Pebble provides exec and file management functions to coordinate with remote systems.

```{toctree}
:titlesonly:
:maxdepth: 1

Manage a remote system <manage-a-remote-system>
```


## Identities

Use named "identities" to allow additional users to access the API.
Expand All @@ -37,3 +49,15 @@ Use named "identities" to allow additional users to access the API.

Manage identities <manage-identities>
```


## API
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved

To integrate Pebble with your automated workflows, you can use the Pebble API.

```{toctree}
:titlesonly:
:maxdepth: 1

Use Pebble API <use-the-pebble-api>
```
140 changes: 140 additions & 0 deletions docs/how-to/manage-a-remote-system.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# How to use Pebble to manage a remote system

Managing server clusters remotely takes time and effort. Servers need regular updates, configuration changes, file transfers, and commands run. Directly managing remote servers or using tools like Ansible, which require SSH, increases overhead and security risks. The [XZ Utils backdoor incident](https://en.wikipedia.org/wiki/XZ_Utils_backdoor) highlighted vulnerabilities associated with SSH access.
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved

Pebble offers commands and an HTTP API over unix socket for remote system management, avoiding the need for extra open ports.
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved

> Note: "remote system" means clients can interact with the Pebble daemon via a unix socket.
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved

## Run commands in a remote system

One common task in system administration is updating and installing packages. With Pebble, we can use the `pebble exec` command to achieve this.

For example, if Pebble is running as user with root privileges, we can use this command to update and install packages in a remote system:
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved

```{terminal}
:input: pebble exec apt update
Hit:1 http://ports.ubuntu.com/ubuntu-ports noble InRelease
Get:2 http://ports.ubuntu.com/ubuntu-ports noble-updates InRelease [126 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports noble-backports InRelease [126 kB]
...
Fetched 3121 kB in 38s (81.5 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
41 packages can be upgraded. Run 'apt list --upgradable' to see them.
```

To install a package, run:

```bash
pebble exec apt install cowsay
```

To confirm the package is successfully installed in the remote system, run:

```{terminal}
:input: pebble exec cowsay moo
_____
< moo >
-----
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
```

For more information on the Pebble `exec` command, see {ref}`reference_pebble_exec_command`.
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved

## Manage files in a remote system

Another common task in a remote system is configuration management. For example, updating configuration files, pushing files to servers, pulling files generated by running services, and so on.

With Pebble, this can be done easily. For example, if we want to install Nginx, create our own website, and serve it on a newly created virtual host, we can first install Nginx:
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved

```bash
pebble exec apt install nginx
```

Then create our website _locally_:

```bash
echo "Hello, Pebble!" > /tmp/index.html
```

Create a directory in the remote system:

```bash
pebble mkdir -p /var/www/pebble
```

Push our local website file to the remote system:

```bash
pebble push /tmp/index.html /var/www/pebble/index.html
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
```

Create a virtual host configuration _locally_:

```
cat <<EOF > /tmp/pebble
server {
listen 81;
listen [::]:81;

server_name example.ubuntu.com;

root /var/www/pebble;
index index.html;

location / {
try_files \$uri \$uri/ =404;
}
}
EOF
```

Push the file to the remote system:

```bash
pebble push /tmp/pebble /etc/nginx/sites-enabled/pebble
```

Activate the newly added virtual host in the remote system by restarting Nginx:

```bash
pebble exec service nginx restart
```

Finally, we can test the final result:
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved

```{terminal}
:input: curl localhost:81
Hello, Pebble!
```

For more information about related Pebble commands, see:

- {ref}`reference_pebble_ls_command`
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
- {ref}`reference_pebble_mkdir_command`
- {ref}`reference_pebble_rm_command`
- {ref}`reference_pebble_push_command`
- {ref}`reference_pebble_pull_command`

## Use the API

In the previous sections, we used Pebble commands to run commands and manage files. When automating these tasks, we can use the HTTP API that Pebble provides.

For example, to push a file to the remote system, we can POST to the `/v1/files` endpoint:

```bash
curl --unix-socket /path/to/.pebble.socket -XPOST http://_/v1/files -H "Content-Type: multipart/form-data" -F request='{"action": "write", "files": [{"path": "/var/www/pebble/index.html", "make-dirs": true, "permissions": "644"}]}' -F 'files=@/tmp/index.html;type=application/octet-stream;filename=/var/www/pebble/index.html'
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
```

We can also use {ref}`api_go_client` and {ref}`api_python_client` for API access.
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved

## See more

- [How to use the Pebble API to manage services](/how-to/use-the-pebble-api).
- [API spec](/reference/api).
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading