mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: dind SIGINT and SIGCHLD changes (#771)
1) in dind, prevent SIGINT reaching to dockerd. This kills docker and prevents shutdown as fn server is trying to stop. 2) as init process, always reap child processes.
This commit is contained in:
@@ -4,10 +4,13 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/fnproject/fn/api/common"
|
"github.com/fnproject/fn/api/common"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -55,3 +58,34 @@ func contextWithSignal(ctx context.Context, signals ...os.Signal) (context.Conte
|
|||||||
}()
|
}()
|
||||||
return newCTX, halt
|
return newCTX, halt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Installs a child process reaper if init process
|
||||||
|
func installChildReaper() {
|
||||||
|
// assume responsibilities of init process if running as init process for Linux
|
||||||
|
if runtime.GOOS != "linux" || os.Getpid() != 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var sigs = make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigs, syscall.SIGCHLD)
|
||||||
|
|
||||||
|
// we run this forever and leak a go routine. As init, we must
|
||||||
|
// reap our children until the very end, so this is OK.
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
<-sigs
|
||||||
|
for {
|
||||||
|
var status syscall.WaitStatus
|
||||||
|
var rusage syscall.Rusage
|
||||||
|
|
||||||
|
pid, err := syscall.Wait4(-1, &status, syscall.WNOHANG, &rusage)
|
||||||
|
// no children
|
||||||
|
if pid <= 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Infof("Child terminated pid=%d err=%v status=%v usage=%v", pid, err, status, rusage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|||||||
@@ -394,6 +394,8 @@ func (s *Server) startGears(ctx context.Context, cancel context.CancelFunc) {
|
|||||||
|
|
||||||
logrus.WithField("type", s.nodeType).Infof("Fn serving on `%v`", listen)
|
logrus.WithField("type", s.nodeType).Infof("Fn serving on `%v`", listen)
|
||||||
|
|
||||||
|
installChildReaper()
|
||||||
|
|
||||||
server := http.Server{
|
server := http.Server{
|
||||||
Addr: listen,
|
Addr: listen,
|
||||||
Handler: s.Router,
|
Handler: s.Router,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -euo pipefail
|
||||||
|
|
||||||
fsdriver=$(grep -Eh -w -m1 "overlay|aufs" /proc/filesystems | cut -f2)
|
fsdriver=$(grep -Eh -w -m1 "overlay|aufs" /proc/filesystems | cut -f2)
|
||||||
if [ $fsdriver == "overlay" ]; then
|
if [ $fsdriver == "overlay" ]; then
|
||||||
@@ -10,6 +10,8 @@ mtu=$(ip link show dev $(ip route |
|
|||||||
awk '$1 == "default" { print $NF }') |
|
awk '$1 == "default" { print $NF }') |
|
||||||
awk '{for (i = 1; i <= NF; i++) if ($i == "mtu") print $(i+1)}')
|
awk '{for (i = 1; i <= NF; i++) if ($i == "mtu") print $(i+1)}')
|
||||||
|
|
||||||
|
# activate job control, prevent docker process from receiving SIGINT
|
||||||
|
set -m
|
||||||
dockerd-entrypoint.sh --storage-driver=$fsdriver --mtu=$mtu &
|
dockerd-entrypoint.sh --storage-driver=$fsdriver --mtu=$mtu &
|
||||||
|
|
||||||
# give docker a few seconds
|
# give docker a few seconds
|
||||||
|
|||||||
Reference in New Issue
Block a user