Skip to content
Snippets Groups Projects
Commit d839ed99 authored by ale's avatar ale
Browse files

Make the Debian package preserve its state on restart

parent 25683705
No related branches found
No related tags found
1 merge request!35Add state load/dump logic to the main server binary
Pipeline #45281 failed
...@@ -22,13 +22,13 @@ import ( ...@@ -22,13 +22,13 @@ import (
var ( var (
addr = flag.String("addr", ":5006", "address to listen on") addr = flag.String("addr", ":5006", "address to listen on")
configFile = flag.String("config", "/etc/keystore/config.yml", "path of config file") configFile = flag.String("config", "/etc/keystore/config.yml", "path of config file")
stateFile = flag.String("state-file", "", "path of state file for transparent restarts")
) )
// Config wraps the keystore server.Config together with the HTTP // Config wraps the keystore server.Config together with the HTTP
// server config in a single object for YAML deserialization. // server config in a single object for YAML deserialization.
type Config struct { type Config struct {
server.Config `yaml:",inline"` server.Config `yaml:",inline"`
StateFile string `yaml:"state_file"`
ServerConfig *serverutil.ServerConfig `yaml:"http_server"` ServerConfig *serverutil.ServerConfig `yaml:"http_server"`
} }
...@@ -94,8 +94,8 @@ func main() { ...@@ -94,8 +94,8 @@ func main() {
} }
prometheus.MustRegister(server.NewKeystoreCollector(ks)) prometheus.MustRegister(server.NewKeystoreCollector(ks))
if config.StateFile != "" { if *stateFile != "" {
if err := loadState(ks, config.StateFile); err != nil { if err := loadState(ks, *stateFile); err != nil {
log.Printf("error loading state: %v", err) log.Printf("error loading state: %v", err)
} }
} }
...@@ -106,8 +106,8 @@ func main() { ...@@ -106,8 +106,8 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
if config.StateFile != "" { if *stateFile != "" {
if err := dumpState(ks, config.StateFile); err != nil { if err := dumpState(ks, *stateFile); err != nil {
log.Fatalf("error dumping state: %v", err) log.Fatalf("error dumping state: %v", err)
} }
} }
......
10 13
...@@ -2,7 +2,7 @@ Source: keystore ...@@ -2,7 +2,7 @@ Source: keystore
Section: admin Section: admin
Priority: optional Priority: optional
Maintainer: Autistici/Inventati <debian@autistici.org> Maintainer: Autistici/Inventati <debian@autistici.org>
Build-Depends: debhelper (>=9), golang-any (>=1.11), dh-golang Build-Depends: debhelper (>=13), golang-any (>=1.14), dh-golang
Standards-Version: 3.9.6 Standards-Version: 3.9.6
Package: keystored Package: keystored
......
ADDR=:5006 ADDR=:5006
STATE_FILE=/var/lib/keystored/reload-state
...@@ -5,8 +5,8 @@ After=network.target ...@@ -5,8 +5,8 @@ After=network.target
[Service] [Service]
User=keystored User=keystored
Group=keystored Group=keystored
EnvironmentFile=-/etc/default/keystored EnvironmentFile=/etc/default/keystored
ExecStart=/usr/bin/keystored --addr $ADDR ExecStart=/usr/bin/keystored --addr $ADDR --state-file $STATE_FILE
Restart=always Restart=always
# Hardening # Hardening
...@@ -16,6 +16,7 @@ PrivateDevices=yes ...@@ -16,6 +16,7 @@ PrivateDevices=yes
ProtectHome=yes ProtectHome=yes
ProtectSystem=full ProtectSystem=full
ReadOnlyDirectories=/ ReadOnlyDirectories=/
ReadWriteDirectories=/var/lib/keystored
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CapabilityBoundingSet=CAP_NET_BIND_SERVICE
[Install] [Install]
......
d /var/lib/keystored 700 keystored keystored
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment