Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IRMA
Github mirrors
irmago
Commits
5b9cb8d9
Commit
5b9cb8d9
authored
Mar 11, 2019
by
Sietse Ringers
Browse files
Do graceful shutdown on ctrl-c in irma server
parent
4c02373c
Changes
1
Hide whitespace changes
Inline
Side-by-side
server/irmad/cmd/root.go
View file @
5b9cb8d9
...
...
@@ -2,8 +2,10 @@ package cmd
import
(
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"github.com/go-errors/errors"
"github.com/mitchellh/mapstructure"
...
...
@@ -28,8 +30,31 @@ var RootCommand = &cobra.Command{
if
err
!=
nil
{
die
(
errors
.
WrapPrefix
(
err
,
"Failed to configure server"
,
0
))
}
if
err
:=
serv
.
Start
(
conf
);
err
!=
nil
{
die
(
errors
.
WrapPrefix
(
err
,
"Failed to start server"
,
0
))
stopped
:=
make
(
chan
struct
{})
interrupt
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
interrupt
,
os
.
Interrupt
,
syscall
.
SIGTERM
)
go
func
()
{
if
err
:=
serv
.
Start
(
conf
);
err
!=
nil
{
die
(
errors
.
WrapPrefix
(
err
,
"Failed to start server"
,
0
))
}
conf
.
Logger
.
Debug
(
"Server stopped"
)
stopped
<-
struct
{}{}
}()
for
{
select
{
case
<-
interrupt
:
conf
.
Logger
.
Debug
(
"Caught interrupt"
)
serv
.
Stop
()
// causes serv.Start() above to return
conf
.
Logger
.
Debug
(
"Sent stop signal to server"
)
case
<-
stopped
:
conf
.
Logger
.
Info
(
"Exiting"
)
close
(
stopped
)
close
(
interrupt
)
return
}
}
},
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment