Skip to content

Commit

Permalink
Clean up in systemd via SIGINT
Browse files Browse the repository at this point in the history
The only signal understood by the program is SIGINT, via the convenient
ctrl_c handler by tokio. Systemd sends SIGTERM/SIGKILL by default,
so let's override that to give the application a chance to clean up.
The real solution is supporting SIGTERM directly.
  • Loading branch information
conorsch committed Aug 7, 2021
1 parent fdb4306 commit 358ae13
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,18 @@ Running as a service
--------------------

The deb package ships with a systemd config file.
To use it, choose a unique name for the service (e.g. `foo`),
To use it, choose a unique name for the service (e.g. `minikube`),
and make sure your API token is exported:

```
sudo mkdir -p /etc/systemd/system/[email protected]/
printf '[Service]\nEnvironment="DIGITALOCEAN_API_TOKEN=%s"\n' "$DIGITALOCEAN_API_TOKEN" > /etc/systemd/system/[email protected]/override.conf
sudo systemctl daemon-reload
sudo systemctl restart innisfree@foo
sudo journalctl -af -u innisfree@foo
```

You can also override more settings:

```
cat /etc/systemd/system/innisfree\@minikube.service.d/override.conf
[Service]
Environment="DIGITALOCEAN_API_TOKEN=<REDACTED>"
# Override any settings from the shipped service
User=conorsch
ExecStart=
ExecStart=/bin/bash -c "innisfree up --floating-ip 1.2.3.4 --dest-ip $(su conorsch -c 'minikube ip') -p 443/TCP --name k8s"
ExecStart=/bin/bash -c "innisfree up --floating-ip 1.2.3.4 --dest-ip $(minikube ip) -p 443/TCP --name k8s"
```

The above will proxy a connection to a local minikube installation.
Expand Down
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
* [x] Add lots of results for better error handling
* [x] Add doctor subcommand for checking

* [ ] Service stop should clean up resources
* [x] Service stop should clean up resources
* [ ] Support SIGTERM and SIGKILL signals
* [x] Make 'release' builds reproducible
* [ ] Make deb package builds reproducible
* [x] Use a build.rs file for setting remap on rustcflags https://doc.rust-lang.org/cargo/reference/build-scripts.html
Expand Down
2 changes: 2 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Wants=network-online.target nss-lookup.target
Type=simple
Environment="RUST_LOG=info"
ExecStart=/usr/bin/innisfree up --name %i
# Hack SIGINT, since SIGTERM not yet supported
KillSignal=SIGINT
Restart=always

[Install]
Expand Down
2 changes: 1 addition & 1 deletion src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl InnisfreeManager {
Ok(()) => {
warn!("Received stop signal, exiting gracefully");
self.clean().await;
debug!("Clean up complete, exiting!");
info!("Clean up complete, exiting");
std::process::exit(0);
}
Err(e) => {
Expand Down

0 comments on commit 358ae13

Please sign in to comment.