mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-13 20:08:05 +08:00
114 lines
4.2 KiB
Diff
114 lines
4.2 KiB
Diff
--- a/dockerd/files/dockerd.init
|
|
+++ b/dockerd/files/dockerd.init
|
|
@@ -2,6 +2,7 @@
|
|
|
|
USE_PROCD=1
|
|
START=99
|
|
+STOP=10
|
|
|
|
extra_command "uciadd" "<interface> <device> <zone> Add docker bridge configuration to network and firewall uci config"
|
|
extra_command "ucidel" "<interface> <device> <zone> Delete docker bridge configuration from network and firewall uci config"
|
|
@@ -238,6 +239,8 @@ start_service() {
|
|
procd_set_param command /usr/bin/dockerd --config-file="${DOCKERD_CONF}"
|
|
fi
|
|
procd_set_param limits nofile="${nofile} ${nofile}"
|
|
+ # Give dockerd the time to stop the containers before it gets killed
|
|
+ procd_set_param term_timeout 300
|
|
procd_close_instance
|
|
}
|
|
|
|
@@ -293,8 +296,50 @@ iptables_add_blocking_rule() {
|
|
config_list_foreach "${cfg}" blocked_interfaces handle_iptables_rule "${device}" "${extra_iptables_args}"
|
|
}
|
|
|
|
+# Read procd's notifications until one contains the given text, or none comes for the given seconds
|
|
+procd_notification() {
|
|
+ local line
|
|
+
|
|
+ while read -r -t "${2}" line <&3; do
|
|
+ case "${line}" in
|
|
+ *"${1}"*) return 0 ;;
|
|
+ esac
|
|
+ done
|
|
+ return 1
|
|
+}
|
|
+
|
|
stop_service() {
|
|
- if /etc/init.d/dockerd running; then
|
|
- service_stop "/usr/bin/dockerd"
|
|
- fi
|
|
+ local i=0
|
|
+
|
|
+ procd_running dockerd || return 0
|
|
+
|
|
+ # Subscribe to procd's notifications before it stops dockerd, to learn when it is done.
|
|
+ # The subscriber leaves procd's lock (fd 1000) to this script, which releases it on exit.
|
|
+ STOP_EVENTS="/var/run/dockerd.stop.$$"
|
|
+ mkfifo "${STOP_EVENTS}" || return 0
|
|
+ ubus -t 330 subscribe service > "${STOP_EVENTS}" 1000>&- &
|
|
+ STOP_SUBSCRIBER=$!
|
|
+ exec 3< "${STOP_EVENTS}"
|
|
+
|
|
+ # The subscription takes effect a moment later, and a stop notified before it would be missed:
|
|
+ # wait until procd passes on an event sent to itself
|
|
+ while [ "${i}" -lt 10 ]; do
|
|
+ ubus call service event '{ "type": "dockerd.stopping", "data": {} }'
|
|
+ if procd_notification '"type":"dockerd.stopping"' 1; then
|
|
+ STOP_SUBSCRIBED=1
|
|
+ return 0
|
|
+ fi
|
|
+ i=$((i + 1))
|
|
+ done
|
|
+}
|
|
+
|
|
+service_stopped() {
|
|
+ [ -n "${STOP_EVENTS}" ] || return 0
|
|
+
|
|
+ # Wait for dockerd, which exits after stopping the containers, so that a shutdown unmounts the data root after them
|
|
+ [ -n "${STOP_SUBSCRIBED}" ] && procd_notification '"service.stop": {"service":"dockerd"}' 330
|
|
+ exec 3<&-
|
|
+ # A restart ignores SIGTERM while it stops dockerd, and so does the subscriber it started
|
|
+ kill -KILL "${STOP_SUBSCRIBER}" 2> /dev/null
|
|
+ rm -f "${STOP_EVENTS}"
|
|
}
|
|
|
|
--- a/dockerd/Makefile
|
|
+++ b/dockerd/Makefile
|
|
@@ -47,6 +47,8 @@ define Package/dockerd
|
|
+kmod-veth \
|
|
+tini \
|
|
+uci-firewall \
|
|
+ +fuse-overlayfs \
|
|
+ +kmod-vxlan +kmod-macvlan +kmod-dummy +kmod-crypto-gcm +kmod-crypto-seqiv +kmod-crypto-ghash +kmod-ipsec +kmod-nf-nathelper +kmod-nf-nathelper-extra +btrfs-progs \
|
|
@!(mips||mips64||mipsel)
|
|
USERID:=docker:docker
|
|
MENU:=1
|
|
@@ -94,13 +96,13 @@ define Build/Prepare
|
|
$(Build/Prepare/Default)
|
|
|
|
# Verify dependencies are the vendored version
|
|
- $(call EnsureVendoredVersion,../containerd/Makefile,containerd.installer)
|
|
- $(call EnsureVendoredVersion,../runc/Makefile,runc.installer)
|
|
- $(call EnsureVendoredVersion,../tini/Makefile,tini.installer)
|
|
+ $(call EnsureVendoredVersion,../../packages/utils/containerd/Makefile,containerd.installer)
|
|
+ $(call EnsureVendoredVersion,../../packages/utils/runc/Makefile,runc.installer)
|
|
+ $(call EnsureVendoredVersion,../../packages/utils/tini/Makefile,tini.installer)
|
|
|
|
# Verify CLI is the same version
|
|
( \
|
|
- CLI_MAKEFILE="../docker/Makefile"; \
|
|
+ CLI_MAKEFILE="../../packages/utils/docker/Makefile"; \
|
|
CLI_VERSION=$$$$( grep --only-matching --perl-regexp '(?<=PKG_VERSION:=)(.*)' "$$$${CLI_MAKEFILE}" ); \
|
|
if [ "$$$${CLI_VERSION}" != "$(PKG_VERSION)" ]; then \
|
|
echo "ERROR: Expected 'PKG_VERSION:=$(PKG_VERSION)' in '$$$${CLI_MAKEFILE}', found 'PKG_VERSION:=$$$${CLI_VERSION}'"; \
|
|
@@ -142,6 +144,9 @@ define Package/dockerd/install
|
|
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bundles/binary-daemon/dockerd $(1)/usr/bin/
|
|
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bundles/binary-daemon/docker-proxy $(1)/usr/bin/
|
|
|
|
+ $(INSTALL_DIR) $(1)/etc/uci-defaults
|
|
+ $(INSTALL_DATA) ./files/dockerd.uci-defaults $(1)/etc/uci-defaults/dockerd
|
|
+
|
|
$(INSTALL_DIR) $(1)/opt/docker/
|
|
|
|
ifeq ($(CONFIG_DOCKER_CHECK_CONFIG),y)
|