Skip to content

Commit

Permalink
feat: optmize dfget package upgrade support (#804)
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Ma <majinjing3@gmail.com>
  • Loading branch information
jim3ma committed Dec 10, 2021
1 parent 5b502aa commit 9d857ea
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 10 deletions.
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

PROJECT_NAME := "d7y.io/dragonfly/v2"
DFGET_NAME := "dfget"
VERSION := "2.0.0"
SEMVER := "2.0.1"
VERSION_RELEASE := "1"
PKG := "$(PROJECT_NAME)"
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/ | grep -v '\(/test/\)')
GIT_COMMIT := $(shell git rev-parse --verify HEAD --short=7)
GIT_COMMIT_LONG := $(shell git rev-parse --verify HEAD)
DFGET_ARCHIVE_PREFIX := "$(DFGET_NAME)_$(GIT_COMMIT)"
DFGET_ARCHIVE_PREFIX := "$(DFGET_NAME)_$(SEMVER)-$(VERSION_RELEASE)_$(GIT_COMMIT)"

all: help

Expand Down Expand Up @@ -159,10 +160,12 @@ build-rpm-dfget: build-linux-dfget
-v "$(PWD)/LICENSE:/root/License" \
-v "$(PWD)/CHANGELOG.md:/root/CHANGELOG.md" \
-v "$(PWD)/bin:/root/bin" \
-e "VERSION=$(GIT_VERSION)" \
-e "SEMVER=$(SEMVER)" \
-e "VERSION_RELEASE=$(VERSION_RELEASE)" \
goreleaser/nfpm pkg \
--config /root/build/package/nfpm/dfget.yaml \
--target /root/bin/$(DFGET_ARCHIVE_PREFIX)_linux_amd64.rpm
@echo "Build package output: ./bin/$(DFGET_ARCHIVE_PREFIX)_linux_amd64.rpm"
.PHONY: build-rpm-dfget

# Build deb dfget
Expand All @@ -174,10 +177,12 @@ build-deb-dfget: build-linux-dfget
-v "$(PWD)/LICENSE:/root/License" \
-v "$(PWD)/CHANGELOG.md:/root/CHANGELOG.md" \
-v "$(PWD)/bin:/root/bin" \
-e "VERSION=$(GIT_VERSION)" \
-e "SEMVER=$(SEMVER)" \
-e "VERSION_RELEASE=$(VERSION_RELEASE)" \
goreleaser/nfpm pkg \
--config /root/build/package/nfpm/dfget.yaml \
--target /root/bin/$(DFGET_ARCHIVE_PREFIX)_linux_amd64.deb
@echo "Build package output: ./bin/$(DFGET_ARCHIVE_PREFIX)_linux_amd64.deb"
.PHONY: build-deb-dfget

# Generate dfget man page
Expand Down
4 changes: 2 additions & 2 deletions build/package/nfpm/config/dfget.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ scheduler:
# schedule timeout
scheduleTimeout: 10s

# when enable, pprof will be enabled,
# when enabled, pprof will be enabled,
verbose: true
console: false

Expand Down Expand Up @@ -117,7 +117,7 @@ proxy:
key: ""
tcpListen:
# listen address
listen: 0.0.0.0
listen: 127.0.0.1
# listen port, daemon will try to listen
# when this port is not available, daemon will try next port
port: 65001
Expand Down
9 changes: 8 additions & 1 deletion build/package/nfpm/dfget-postinstall.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/bash

if [[ "$D7Y_DEBUG" == "true" ]]; then
set -x
echo post install with param: "$@"
fi

chmod a+s /usr/bin/dfget

which systemctl && (systemctl daemon-reload; systemctl enable dfget-daemon.service)
if [[ -f /bin/systemctl || -f /usr/bin/systemctl ]]; then
systemctl daemon-reload; systemctl enable --now dfget-daemon.service
fi
9 changes: 8 additions & 1 deletion build/package/nfpm/dfget-postremove.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#!/bin/bash

which systemctl && systemctl daemon-reload
if [[ "$D7Y_DEBUG" == "true" ]]; then
set -x
echo post remove with param: "$@"
fi

if [[ -f /bin/systemctl || -f /usr/bin/systemctl ]]; then
systemctl daemon-reload
fi
13 changes: 13 additions & 0 deletions build/package/nfpm/dfget-preinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

if [[ "$D7Y_DEBUG" == "true" ]]; then
set -x
echo pre install with param: "$@"
fi

# stop dfget daemon before upgrading
if [[ -f "/etc/systemd/system/dfget-daemon.service" ]]; then
if [[ -f /bin/systemctl || -f /usr/bin/systemctl ]]; then
systemctl stop dfget-daemon.service
fi
fi
26 changes: 25 additions & 1 deletion build/package/nfpm/dfget-preremove.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
#!/bin/bash

which systemctl && (systemctl stop dfget-daemon.service; systemctl disable dfget-daemon.service)
if [[ "$D7Y_DEBUG" == "true" ]]; then
set -x
echo pre remove with param: "$@"
fi

upgrade=0

# in rpm install:
# refer: https://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch09s04s05.html
if [[ "$1" -gt 0 ]]; then
upgrade=1
fi

# in deb install
# refer: https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html
if [[ "$1" =~ "upgrade" ]]; then
upgrade=1
fi

# not in upgrade, purge systemd service
if [[ "$upgrade" -eq 0 ]]; then
if [[ -f /bin/systemctl || -f /usr/bin/systemctl ]]; then
systemctl stop dfget-daemon.service; systemctl disable dfget-daemon.service
fi
fi
6 changes: 5 additions & 1 deletion build/package/nfpm/dfget.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: dfget
arch: amd64
platform: linux
version: ${VERSION}
epoch: 2
version: v${SEMVER}
version_schema: semver
release: ${VERSION_RELEASE}
section: default
priority: extra
description: dfget is the client of Dragonfly used to download and upload files
Expand Down Expand Up @@ -45,6 +48,7 @@ contents:
dst: /opt/dragonfly/fix.dfget-daemon.cpuset.sh

scripts:
preinstall: /root/build/package/nfpm/dfget-preinstall.sh
postinstall: /root/build/package/nfpm/dfget-postinstall.sh
preremove: /root/build/package/nfpm/dfget-preremove.sh
postremove: /root/build/package/nfpm/dfget-postremove.sh
1 change: 1 addition & 0 deletions build/package/nfpm/systemd/fix.dfget-daemon.cpuset.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh

# fix cpu set not settled in old kernel
mkdir -p /sys/fs/cgroup/cpuset,cpu,cpuacct/dragonfly.slice/dfget-daemon.service
cat /sys/fs/cgroup/cpuset,cpu,cpuacct/cpuset.cpus > \
/sys/fs/cgroup/cpuset,cpu,cpuacct/dragonfly.slice/cpuset.cpus
Expand Down

0 comments on commit 9d857ea

Please sign in to comment.