This commit is contained in:
Daniel J Walsh 2016-10-13 17:18:20 +00:00 committed by GitHub
commit 6a686f51aa
7 changed files with 90 additions and 1 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ pause/pause.o
/docs/ocid.8
/docs/ocid.conf.5
vendor/src/github.com/kubernetes-incubator/cri-o
ocid.conf

View file

@ -44,7 +44,11 @@ ocid: ${OCID_LINK}
ocic: ${OCID_LINK}
go build -o ocic ./cmd/client/
ocid.conf: ocid
./ocid --config="" config --default > ocid.conf
clean:
rm -f ocid.conf
rm -f ocic ocid
rm -f ${OCID_LINK}
rm -f conmon/conmon.o conmon/conmon
@ -83,7 +87,7 @@ docs/%.5: docs/%.5.md
docs: $(MANPAGES_MD:%.md=%)
install:
install: ocid.conf
install -D -m 755 ocid ${INSTALLDIR}/ocid
install -D -m 755 ocic ${INSTALLDIR}/ocic
install -D -m 755 conmon/conmon $(PREFIX)/libexec/ocid/conmon
@ -92,8 +96,13 @@ install:
install -m 644 $(wildcard docs/*.8.md) $(PREFIX)/share/man/man8
install -d $(PREFIX)/share/man/man5
install -m 644 $(wildcard docs/*.5.md) $(PREFIX)/share/man/man5
install -D -m 644 ocid.service $(PREFIX)/lib/systemd/system
install -D -m 644 ocid.conf $(DESTDIR)/etc
uninstall:
systemctl stop ocid.service
systemctl disable ocid.service
rm -f $(PREFIX)/lib/systemd/system/ocid.service
rm -f ${INSTALLDIR}/{ocid,ocic}
rm -f $(PREFIX)/libexec/ocid/{conmon,pause}
for i in $(wildcard docs/*.8.md); do \

View file

@ -0,0 +1,20 @@
// +build linux
package main
import (
"github.com/Sirupsen/logrus"
systemdDaemon "github.com/coreos/go-systemd/daemon"
)
func sdNotify() {
if err := systemdDaemon.SdNotify("READY=1"); err != nil {
logrus.Warnf("Failed to sd_notify systemd: %v", err)
}
}
// notifySystem sends a message to the host when the server is ready to be used
func notifySystem() {
// Tell the init daemon we are accepting requests
go sdNotify()
}

View file

@ -205,6 +205,10 @@ func main() {
runtime.RegisterRuntimeServiceServer(s, service)
runtime.RegisterImageServiceServer(s, service)
// after the daemon is done setting up we can notify systemd api
notifySystem()
if err := s.Serve(lis); err != nil {
logrus.Fatal(err)
}

View file

@ -46,6 +46,7 @@ case $# in
;;
esac
clone git github.com/coreos/go-systemd/daemon
clone git github.com/BurntSushi/toml v0.2.0
clone git github.com/Sirupsen/logrus v0.10.0
clone git github.com/containers/image f6f11ab5cf8b1e70ef4aa3f8b6fdb4b671d16abd

23
ocid.service Normal file
View file

@ -0,0 +1,23 @@
[Unit]
Description=Open Container Initiative Daemon
Documentation=https://github.com/kubernetes-incubator/cri-o
After=network.target
[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/ocid-storage
EnvironmentFile=-/etc/sysconfig/ocid-network
Environment=GOTRACEBACK=crash
ExecStart=/usr/bin/ocid \
$OCID_STORAGE_OPTIONS \
$OCID_NETWORK_OPTIONS \
ExecReload=/bin/kill -s HUP $MAINPID
TasksMax=8192
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Restart=on-abnormal
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,31 @@
// Code forked from Docker project
package daemon
import (
"errors"
"net"
"os"
)
var SdNotifyNoSocket = errors.New("No socket")
// SdNotify sends a message to the init daemon. It is common to ignore the error.
func SdNotify(state string) error {
socketAddr := &net.UnixAddr{
Name: os.Getenv("NOTIFY_SOCKET"),
Net: "unixgram",
}
if socketAddr.Name == "" {
return SdNotifyNoSocket
}
conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr)
if err != nil {
return err
}
defer conn.Close()
_, err = conn.Write([]byte(state))
return err
}