-
Notifications
You must be signed in to change notification settings - Fork 5
Docs: add systemd agent service configuration to Polykey CLI guide #152
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
base: staging
Are you sure you want to change the base?
Conversation
b32e5a8
to
af386fc
Compare
The proper person to review this isn't me anymore. It's @brynblack. And very importantly you must actually confirm that this is true. Don't just write docs blindly. You have to sanity check what you're writing to confirm that it actually works. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it looks good apart from the instructions, which are more intended for a Linux-agnostic solution, which we don't really have yet. The Polykey Agent is designed primarily at the moment for NixOS.
A few modifications will need to be made to the instructions to clarify the setup for NixOS devices instead of a generic solution. However, the explanations on most things look good.
### Setup Instructions (User Mode) | ||
|
||
1. Ensure the Polykey binary is installed and accessible via `$PATH`. | ||
2. Copy the service file to: | ||
|
||
```sh | ||
mkdir -p ~/.config/systemd/user | ||
cp polykey-agent.service ~/.config/systemd/user/ | ||
``` | ||
|
||
3. Enable and start the service: | ||
|
||
```sh | ||
systemctl --user daemon-reload | ||
systemctl --user enable polykey-agent | ||
systemctl --user start polykey-agent | ||
``` | ||
|
||
4. Verify it's running: | ||
|
||
```sh | ||
systemctl --user status polykey-agent | ||
journalctl --user -u polykey-agent | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section needs to explain how to set up Polykey using Nix configurations, as that is how the service is actually set up. It does not use .service
files. Instead, you configure it like the following, under your home-manager
service (at least for the user-level service):
polykey = {
enable = true;
passwordFilePath = "%h/.polykeypass";
recoveryCodeOutPath = "%h/.polykeyrecovery";
};
enable
will enable the service.passwordFilePath
will set the path to grab the vault password from.recoveryCodeOutPath
will set where to create/grab the recovery code from.
There may need to be an explanation on how Polykey is integrated into a NixOS system.
Take a look at:
## Services Module (System Services) | ||
|
||
The `services` module sets up a root-owned service that: | ||
|
||
- Runs globally for all users. | ||
- Is launched at boot. | ||
- Is managed from `/etc/systemd/system/`. | ||
|
||
### Setup Instructions (System Mode) | ||
|
||
1. Copy the service file to: | ||
|
||
```sh | ||
sudo cp polykey-agent.service /etc/systemd/system/ | ||
``` | ||
|
||
2. Enable and start the service: | ||
|
||
```sh | ||
sudo systemctl daemon-reload | ||
sudo systemctl enable polykey-agent | ||
sudo systemctl start polykey-agent | ||
``` | ||
|
||
3. Check status: | ||
|
||
```sh | ||
sudo systemctl status polykey-agent | ||
sudo journalctl -u polykey-agent | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to also be inline with the comment I put above. There is typically no need to manually modify service files under a NixOS system. Unless in the future we make a generic Linux-agnostic version of the Polykey Agent.
But make sure to distinguish the system-level service from the user-level service.
## Configuration Details | ||
|
||
The service files can be customized: | ||
|
||
- `ExecStart` can point to any valid Polykey binary. | ||
- `Environment` variables like `NODE_ENV`, `POLYKEY_DATA_PATH` can be passed in. | ||
- Restart policies and timeouts can be modified. | ||
|
||
To override a system service without editing the base file: | ||
|
||
```sh | ||
sudo systemctl edit polykey-agent | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The service can be customised, but not through service files. It is done using the home-manager
configuration, as described in my first comment. Make sure to look at the links I put in it.
## Troubleshooting | ||
|
||
- **"Service not found"**: | ||
|
||
- Run `daemon-reload` after copying or editing unit files. | ||
|
||
- **"Permission denied"**: | ||
|
||
- Ensure system-level services are started with `sudo`. | ||
|
||
- **Service not starting**: | ||
|
||
- Run `journalctl -u polykey-agent` for logs. | ||
|
||
- **User services not auto-starting**: | ||
|
||
- Check that `linger` is enabled for the user: | ||
|
||
```sh | ||
sudo loginctl enable-linger $USER | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This technically is valid, as services can be manually restarted or analysed if there are problems. However, the daemon-reload
part is if you are manually editing the service files, which isn't really needed for NixOS.
Definitely add an explainer on how to check the status of the service, using commands such as:
systemctl status --user polykey.service
- checks the status of the service
systemctl restart --user polykey.service
- restarts the service
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Christina doesn't have a nix system or even a linux system, so she can't run the systemctl commands herself.
This is the output of systemctl status --user polykey.service
on my system which you can use for reference.
[aryanj@zenith:~]$ systemctl --user status polykey.service
● polykey.service - Polykey Agent
Loaded: loaded (/home/aryanj/.config/systemd/user/polykey.service; enabled; preset: ignored)
Active: active (running) since Wed 2025-05-21 06:02:43 AEST; 5h 23min ago
Invocation: 4bb789c30b8d4a398da384b83e7bbb34
Process: 1007615 ExecStartPre=/nix/store/2y0dbl6jmvcwrv4h549d0pgcm3dl8p4k-polykey-cli-0.18.13/bin/polykey --password-file /home/aryanj/.pkpass --node-path /home/ary>
Main PID: 1007651 (polykey-agent)
Tasks: 41 (limit: 37944)
Memory: 497.7M (peak: 715.4M)
CPU: 1h 41min 59.690s
CGroup: /user.slice/user-1000.slice/[email protected]/app.slice/polykey.service
└─1007651 polykey-agent
May 21 11:24:19 zenith polykey[1007651]: WARN:polykey.PolykeyAgent.task v0q1d4u6t5to0193h3sb26b4810:Failed - Reason: ErrorProviderCall
May 21 11:24:19 zenith polykey[1007651]: WARN:polykey.PolykeyAgent.task v0q1d4u6trdo01efitk10jlvfdg:Failed - Reason: ErrorProviderCall
May 21 11:24:52 zenith polykey[1007651]: WARN:polykey.PolykeyAgent.task v0q1d4unqqho014bu3oicllik2k:Failed - Reason: ErrorProviderCall
May 21 11:25:12 zenith polykey[1007651]: WARN:polykey.PolykeyAgent.task v0q1d4v1h09o0137uglrcpi2dno:Failed - Reason: ErrorProviderCall
(... more logs)
When you run systemctl restart --user polykey.service
, it should not give you any output but polykey should be restarted in the background automatically.
e4f029d
to
4c010b5
Compare
Description
This PR adds comprehensive documentation for the new systemd-based service management modules introduced in Polykey-CLI PR #138. It includes:
This improves usability, aligns the documentation with the latest features, and sets the foundation for broader secure deployment patterns.
Issues Fixed
Tasks
Final checklist