Skip to content

Commit

Permalink
Merge pull request kata-containers#41 from jcvenegas/install-target
Browse files Browse the repository at this point in the history
makefile: Add install target
  • Loading branch information
WeiZhang555 committed Dec 6, 2017
2 parents 2cf663b + 32dceae commit 02b4784
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
kata-agent
kata-agent.service
agent
40 changes: 38 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
TARGET = kata-agent

$(TARGET):
DESTDIR :=
PREFIX := /usr
BINDIR := $(PREFIX)/bin
# Define if agent will be installed as init
INIT := no
# Path to systemd unit directory if installed as not init.
UNIT_DIR := /usr/lib/systemd/system

GENERATED_FILES :=

ifeq ($(INIT),no)
# Unit file to start kata agent in systemd systems
UNIT_FILES = kata-agent.service
GENERATED_FILES := $(UNIT_FILES)
# Target to be reached in systemd services
UNIT_FILES += kata-containers.target
endif

$(TARGET): $(GENERATED_FILES)
go build -o $@

install:
install -D $(TARGET) $(DESTDIR)$(BINDIR)/$(TARGET)
ifeq ($(INIT),no)
@echo "Installing systemd unit files..."
$(foreach f,$(UNIT_FILES),$(call INSTALL_FILE,$f,$(UNIT_DIR)))
endif

.PHONY: clean
clean:
rm -f $(TARGET)
rm -f $(TARGET) $(GENERATED_FILES)

define INSTALL_FILE
install -D -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
endef

$(GENERATED_FILES): %: %.in
@mkdir -p `dirname $@`
@sed \
-e 's|[@]bindir[@]|$(BINDIR)|g' \
-e 's|[@]kata-agent[@]|$(TARGET)|g' \
"$<" > "$@"
14 changes: 14 additions & 0 deletions kata-agent.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Kata Containers Agent
Documentation=https://github.com/kata-containers/agent
Wants=kata-containers.target

[Service]
# Send agent output to tty to allow capture debug logs
# from a VM serial port
StandardOutput=tty
Type=simple
ExecStart=@bindir@/@kata-agent@
LimitNOFILE=infinity
ExecStop=/bin/sync ; /usr/bin/systemctl --force poweroff
FailureAction=poweroff
7 changes: 7 additions & 0 deletions kata-containers.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Unit]
Description=Kata Containers Agent Target
Requires=basic.target
Requires=kata-agent.service
Conflicts=rescue.service rescue.target
After=basic.target rescue.service rescue.target
AllowIsolate=yes

0 comments on commit 02b4784

Please sign in to comment.