[rpm] add harmony-setup.sh script

Signed-off-by: Leo Chen <leo@harmony.one>
pull/3309/head
Leo Chen 4 years ago
parent 0be1359e8a
commit 170321eb37
  1. 12
      Makefile
  2. 4
      scripts/rpm/harmony-explorer.cfg
  3. 95
      scripts/rpm/harmony-setup.sh
  4. 4
      scripts/rpm/harmony-validator.cfg
  5. 3
      scripts/rpm/harmony.service
  6. 24
      scripts/rpm/harmony.spec

@ -6,10 +6,10 @@ export LIBRARY_PATH:=$(LD_LIBRARY_PATH)
export DYLD_FALLBACK_LIBRARY_PATH:=$(LD_LIBRARY_PATH)
export GO111MODULE:=on
PKGNAME=harmony
VERSION=2.3.4
VERSION=2.3.5
RPMBUILD=$(HOME)/rpmbuild
.PHONY: all help libs exe race trace-pointer debug debug-kill test test-go test-api test-api-attach linux_static rpm
.PHONY: all help libs exe race trace-pointer debug debug-kill test test-go test-api test-api-attach linux_static deb rpm_init rpm_build rpm
all: libs
bash ./scripts/go_executable_build.sh -S
@ -30,6 +30,7 @@ help:
@echo "linux_static - static build the harmony binary & bootnode along with the MCL & BLS libs (for linux)"
@echo "arm_static - static build the harmony binary & bootnode on ARM64 platform"
@echo "rpm - build a harmony RPM pacakge"
@echo "deb - build a harmony Debian pacakge (todo)"
libs:
make -C $(TOP)/mcl -j8
@ -83,7 +84,7 @@ arm_static:
bash ./scripts/go_executable_build.sh -a arm64 -s
git checkout go.mod
deb_package: rpm
deb: rpm
fpm -s dir -t deb -n $(PKGNAME) -v $(VERSION)-$(COMMIT) --prefix /usr/local bin/harmony
fpm -s pleaserun -t deb -n $(PKGNAME)-service -v $(VERSION) /usr/local/bin/harmony
@ -93,7 +94,9 @@ rpm_init:
mkdir -p $(RPMBUILD)/SOURCES/$(PKGNAME)-$(VERSION)
cp -f bin/harmony $(RPMBUILD)/SOURCES/$(PKGNAME)-$(VERSION)
cp -f scripts/rpm/harmony.service $(RPMBUILD)/SOURCES/$(PKGNAME)-$(VERSION)
cp -f scripts/rpm/harmony-setup.sh $(RPMBUILD)/SOURCES/$(PKGNAME)-$(VERSION)
cp -f scripts/rpm/harmony-sysctl.conf $(RPMBUILD)/SOURCES/$(PKGNAME)-$(VERSION)
cp -f scripts/rpm/harmony-*.cfg $(RPMBUILD)/SOURCES/$(PKGNAME)-$(VERSION)
cp -f scripts/rpm/harmony.spec $(RPMBUILD)/SPECS
(cd $(RPMBUILD)/SOURCES; tar cvf $(PKGNAME)-$(VERSION).tar $(PKGNAME)-$(VERSION))
@ -101,6 +104,3 @@ rpm_build:
rpmbuild --target x86_64 -bb scripts/rpm/harmony.spec
rpm: rpm_init rpm_build
rpm_test: rpm
echo "sudo docker run -it -v $(RPMBUILD):/mnt/rpmbuild tqhh/rpmtest"

@ -0,0 +1,4 @@
# Set SHARD to 0,1,2,3
# It is used to setup RPC endpoint
SHARD=0
TYPE=explorer

@ -0,0 +1,95 @@
#!/usr/bin/env bash
ME=$(basename "$0")
CONFIGDIR=/etc/harmony
VER=v1.0
function usage() {
cat <<-EOT
Usage: $ME [options]
Options:
-t validator/explorer specify the type of the node is explorer or validator (default is: $TYPE)
-s int specify the shard id, only needed if node type is explorer (default is: $SHARD)
-h print this help
-v print out the version of the script
Examples:
$ME -t explorer -s 0
# TODO: interactive mode
EOT
exit 0
}
function _setup_validator_config_file() {
cat<<-EOT > $CONFIGDIR/harmony-validator.cfg
# SHARD set to -1 for normal validator
# The real shard is determined by the blskey
SHARD=-1
TYPE=validator
EOT
pushd ${CONFIGDIR} &> /dev/null
ln -sf harmony-validator.cfg harmony.cfg
popd &> /dev/null
}
function _setup_explorer_config_file() {
cat<<-EOT > $CONFIGDIR/harmony-explorer.cfg
# Set SHARD to 0,1,2,3
# It is used to setup RPC endpoint
SHARD=$SHARD
TYPE=explorer
EOT
pushd ${CONFIGDIR} &> /dev/null
ln -sf harmony-explorer.cfg harmony.cfg
popd &> /dev/null
}
function setup_config_file() {
case $TYPE in
validator) _setup_validator_config_file ;;
explorer) _setup_explorer_config_file ;;
*) usage ;;
esac
}
function restart_systemd_service() {
systemctl daemon-reload
systemctl restart harmony
}
####### default value ######
TYPE=validator
SHARD=-1
while getopts ":t:s:v" opt; do
case ${opt} in
t) TYPE=${OPTARG} ;;
s) SHARD=${OPTARG} ;;
v) echo $VER; exit ;;
*) usage ;;
esac
done
shift $((OPTIND-1))
# validate input parameters
case ${TYPE} in
explorer)
case ${SHARD} in
0|1|2|3) ;;
*) usage ;;
esac
;;
validator)
case ${SHARD} in
-1) ;;
*) usage ;;
esac
;;
*) usage ;;
esac
setup_config_file
restart_systemd_service

@ -0,0 +1,4 @@
# SHARD set to -1 for normal validator
# The real shard is determined by the blskey
SHARD=-1
TYPE=validator

@ -8,7 +8,8 @@ Restart=on-failure
RestartSec=1
User=harmony
WorkingDirectory=/home/harmony
ExecStart=harmony
EnvironmentFile=/etc/harmony/harmony.cfg
ExecStart=harmony --run.shard ${SHARD} --run ${TYPE}
StandardError=syslog
SyslogIdentifier=harmony
StartLimitInterval=0

@ -5,8 +5,8 @@
Name: harmony
Version: 2.3.4
Release: 0%{?dist}
Version: 2.3.5
Release: 0
Summary: harmony blockchain validator node program
License: MIT
@ -24,7 +24,7 @@ BuildRoot: ~/rpmbuild/
%description
Harmony is a sharded, fast finality, low fee, PoS public blockchain.
This is the validator node program for harmony blockchain.
This package contains the validator node program for harmony blockchain.
%global debug_package %{nil}
@ -32,27 +32,31 @@ This is the validator node program for harmony blockchain.
%setup -q
%build
echo make %{?_smp_mflags}
exit 0
%check
./harmony --version
exit
exit 0
%pre
getent group harmony >/dev/null || groupadd -r harmony
getent passwd harmony >/dev/null || \
useradd -r -g harmony -d /home/harmony -m -s /sbin/nologin \
-c "Harmony validator node account" harmony
mkdir -p /home/harmony/.hmy/blskeys
chown -R harmony.harmony /home/harmony
exit 0
%install
install -m 0755 -d ${RPM_BUILD_ROOT}/usr/local/sbin ${RPM_BUILD_ROOT}/etc/systemd/system ${RPM_BUILD_ROOT}/etc/sysctl.d
install -m 0755 -d ${RPM_BUILD_ROOT}/usr/local/sbin ${RPM_BUILD_ROOT}/etc/systemd/system ${RPM_BUILD_ROOT}/etc/sysctl.d ${RPM_BUILD_ROOT}/etc/harmony
install -m 0755 harmony ${RPM_BUILD_ROOT}/usr/local/sbin/
install -m 0755 harmony-setup.sh ${RPM_BUILD_ROOT}/usr/local/sbin/
install -m 0644 harmony.service ${RPM_BUILD_ROOT}/etc/systemd/system/
install -m 0644 harmony-sysctl.conf ${RPM_BUILD_ROOT}/etc/sysctl.d/
install -m 0644 harmony-validator.cfg ${RPM_BUILD_ROOT}/etc/harmony/
install -m 0644 harmony-explorer.cfg ${RPM_BUILD_ROOT}/etc/harmony/
pushd ${RPM_BUILD_ROOT}/etc/harmony; ln -s harmony-validator.cfg harmony.cfg; popd
exit 0
%post
@ -66,8 +70,12 @@ exit 0
%files
/usr/local/sbin/harmony
/usr/local/sbin/harmony-setup.sh
/etc/sysctl.d/harmony-sysctl.conf
/etc/systemd/system/harmony.service
/etc/harmony/harmony-validator.cfg
/etc/harmony/harmony-explorer.cfg
/etc/harmony/harmony.cfg
%doc
%license
@ -75,5 +83,5 @@ exit 0
%changelog
* Tue Aug 18 2020 Leo Chen <leo at harmony dot one> 2.3.4
* Tue Aug 18 2020 Leo Chen <leo at harmony dot one> 2.3.5
- init version of the harmony node program

Loading…
Cancel
Save