From 3eeeb5a20115c23656d422a01798a0d5e94854dc Mon Sep 17 00:00:00 2001 From: Moses Narrow Date: Wed, 23 Oct 2024 16:47:42 -0500 Subject: [PATCH] fix embedded scripts and update systemd service template --- cmd/skywire-cli/commands/rewards/getlogs.sh | 6 +- cmd/skywire-cli/commands/rewards/reward.sh | 20 ++++--- cmd/skywire-cli/commands/rewards/services.go | 59 +++++++++++--------- 3 files changed, 48 insertions(+), 37 deletions(-) diff --git a/cmd/skywire-cli/commands/rewards/getlogs.sh b/cmd/skywire-cli/commands/rewards/getlogs.sh index 4a95b3c93..c0341c5a4 100755 --- a/cmd/skywire-cli/commands/rewards/getlogs.sh +++ b/cmd/skywire-cli/commands/rewards/getlogs.sh @@ -1,10 +1,14 @@ #!/usr/bin/bash -timeout 30.0m unbuffer skywire-cli log --minv v1.3.21 -s $(tail -n1 survey-wl.conf) | tee skywire-cli-log.txt +timeout 30.0m unbuffer skywire-cli log $( [[ ! -z "${_minversion}" ]] && echo "--minv ${_minversion}" ) -s $(tail -n1 survey-wl.conf) | tee skywire-cli-log.txt #echo -e "skywire survey and transport log collection $(date)\n\n$(cat skywire-cli-log.txt)\n" echo -e "skywire survey and transport log collection $(date)\n\n$(cat skywire-cli-log.txt)\n" | tee skywire-cli-log0.txt >> /dev/null echo "finished "$(date) | tee -a skywire-cli-log0.txt mv skywire-cli-log0.txt skywire-cli-log.txt +#Remove surveys below minimum version + +[[ ! -z "${_minversion}" ]] && for f in log_backups/*/node-info.json; do version=$(jq -r '.skywire_version' "$f" | cut -d'-' -f1); if [[ "$(echo -e "${_minversion}\n$version" | sort -V | head -n1)" == "$version" && "$version" != "${_minversion}" ]]; then rm -v "$f"; fi; done + #Delete json files more than 1 week old find log_backups/*/*.json -type f -mmin +$((168 * 60)) -delete find log_collecting/*/*.json -type f -mmin +$((168 * 60)) -delete diff --git a/cmd/skywire-cli/commands/rewards/reward.sh b/cmd/skywire-cli/commands/rewards/reward.sh index a6385acc4..9a044297a 100755 --- a/cmd/skywire-cli/commands/rewards/reward.sh +++ b/cmd/skywire-cli/commands/rewards/reward.sh @@ -12,6 +12,8 @@ #date.txt transaction ID of reward distribution transaction - indicates rewards sent if exists ################################################################################ # Prevent running this script when rewards have already been distributed +[[ ! -z ${_wdate} ]] && [[ -f hist/${_wdate}.txt ]] && echo "Transaction already broadcasted for ${_wdate}" && exit 0 +if [[ -z ${_wdate} ]] ; then [[ -f hist/$(date --date="yesterday" +%Y-%m-%d).txt ]] && echo "Transaction already broadcasted for yesterday" && exit 0 # Determine the date for which to calculate rewards # based on the last file containing the reward transaction that exists @@ -22,24 +24,24 @@ [[ ! -f hist/$(date --date="yesterday" +%Y-%m-%d).txt ]] && _wdate=$(date --date="yesterday" +%Y-%m-%d) ## OR specify a date like yesterday ## #_wdate=$(date --date="yesterday" +%Y-%m-%d) ./reward.sh - +fi #################################################### skywire cli ut --cfu "hist/${_wdate}_ut.json" | tee "hist/${_wdate}_ut.txt" # New reward pool starts November 2nd, 2024 if [[ $(date +%s) -lt $(date -d "2024-11-02" +%s) ]]; then #echo "The date is before November 2nd, 2024." #v1.3.29 - two reward pools - exclude pool 2 - skywire cli rewards --utfile "hist/${_wdate}_ut.json" -x "" -ed ${_wdate} -p log_backups | tee hist/${_wdate}_ineligible.csv - skywire cli rewards --utfile "hist/${_wdate}_ut.json" -x "" -20d ${_wdate} -p log_backups | tee hist/${_wdate}_shares.csv - skywire cli rewards --utfile "hist/${_wdate}_ut.json" -x "" -10d $(date --date="yesterday" +%Y-%m-%d) -p log_backups | tee hist/${_wdate}_rewardtxn0.csv - skywire cli rewards --utfile "hist/${_wdate}_ut.json" -x "" -12d ${_wdate} -p log_backups | tee hist/${_wdate}_stats.txt + skywire cli rewards --utfile "hist/${_wdate}_ut.txt" -x "" -ed ${_wdate} -p log_backups | tee hist/${_wdate}_ineligible.csv + skywire cli rewards --utfile "hist/${_wdate}_ut.txt" -x "" -20d ${_wdate} -p log_backups | tee hist/${_wdate}_shares.csv + skywire cli rewards --utfile "hist/${_wdate}_ut.txt" -x "" -10d ${_wdate} -p log_backups | tee hist/${_wdate}_rewardtxn0.csv + skywire cli rewards --utfile "hist/${_wdate}_ut.txt" -x "" -12d ${_wdate} -p log_backups | tee hist/${_wdate}_stats.txt else #echo "The date is on or after November 2nd, 2024." #v1.3.29 - two reward pools - include pool 2 - skywire cli rewards --utfile "hist/${_wdate}_ut.json" -ed ${_wdate} -p log_backups | tee hist/${_wdate}_ineligible.csv - skywire cli rewards --utfile "hist/${_wdate}_ut.json" -20d ${_wdate} -p log_backups | tee hist/${_wdate}_shares.csv - skywire cli rewards --utfile "hist/${_wdate}_ut.json" -10d $(date --date="yesterday" +%Y-%m-%d) -p log_backups | tee hist/${_wdate}_rewardtxn0.csv - skywire cli rewards --utfile "hist/${_wdate}_ut.json" -12d ${_wdate} -p log_backups | tee hist/${_wdate}_stats.txt + skywire cli rewards --utfile "hist/${_wdate}_ut.txt" -ed ${_wdate} -p log_backups | tee hist/${_wdate}_ineligible.csv + skywire cli rewards --utfile "hist/${_wdate}_ut.txt" -20d ${_wdate} -p log_backups | tee hist/${_wdate}_shares.csv + skywire cli rewards --utfile "hist/${_wdate}_ut.txt" -10d ${_wdate} -p log_backups | tee hist/${_wdate}_rewardtxn0.csv + skywire cli rewards --utfile "hist/${_wdate}_ut.txt" -12d ${_wdate} -p log_backups | tee hist/${_wdate}_stats.txt fi #return exit 0 diff --git a/cmd/skywire-cli/commands/rewards/services.go b/cmd/skywire-cli/commands/rewards/services.go index bbcab8394..4deff05bb 100644 --- a/cmd/skywire-cli/commands/rewards/services.go +++ b/cmd/skywire-cli/commands/rewards/services.go @@ -20,48 +20,53 @@ var rewardSH []byte //go:embed getlogs.sh var getlogsSH []byte -const testSH = `#!/bin/bash -echo "Hello World"` - var ( - getlogssh bool - rewardsh bool - testsh bool + getlogsshMinVer string + rewardshDate string ) func init() { RootCmd.AddCommand( scriptCmd, ) - scriptCmd.Flags().BoolVarP(&getlogssh, "getlogs", "g", false, "print getlogs.sh") - scriptCmd.Flags().BoolVarP(&rewardsh, "reward", "r", false, "print reward.sh") - scriptCmd.Flags().BoolVarP(&testsh, "test", "t", false, "print test.sh") - scriptCmd.Flags().MarkHidden("test") //nolint + scriptCmd.AddCommand( + getlogsCmd, + rewardCmd, + ) + + getlogsCmd.Flags().StringVarP(&getlogsshMinVer, "minv", "m", "", "minimum version") + rewardCmd.Flags().StringVarP(&rewardshDate, "date", "d", "", "date for which to calculate rewards") } var scriptCmd = &cobra.Command{ Use: "script", Short: "print reward system scripts", - Long: `Print the reward system scripts. Pipe to bash to execute. - $ skywire cli rewards script -t | bash - Hello World`, + Long: `Print the reward system scripts. Pipe to bash to execute.`, +} + +var getlogsCmd = &cobra.Command{ + Use: "getlogs", + Short: "getlogs.sh - `skywire cli log` wrapper", + Long: "getlogs.sh - `skywire cli log` wrapper", Run: func(_ *cobra.Command, _ []string) { - if getlogssh && rewardsh { - log.Fatal("mutually exclusive flags") - } - if getlogssh { - fmt.Println(string(getlogsSH)) - os.Exit(0) + if getlogsshMinVer != "" { + fmt.Println("_minversion=" + getlogsshMinVer) } - if rewardsh { - fmt.Println(string(rewardSH)) - os.Exit(0) - } - if testsh { - fmt.Println(string(testSH)) - os.Exit(0) + fmt.Println(string(getlogsSH)) + }, +} + +var rewardCmd = &cobra.Command{ + Use: "reward", + Short: "reward.sh - `skywire cli rewards` wrapper script", + Long: "reward.sh - `skywire cli rewards` wrapper script", + Run: func(_ *cobra.Command, _ []string) { + if rewardshDate != "" { + fmt.Println("_wdate=" + rewardshDate) } + fmt.Println(string(rewardSH)) + os.Exit(0) }, } @@ -200,7 +205,7 @@ After=network.target Type=simple User={{.User}} WorkingDirectory={{.Dir}}/rewards -ExecStart=/bin/bash -c 'skywire cli rewards script -g | bash && skywire cli rewards script -r | bash ; exit 0' +ExecStart=/bin/bash -c 'skywire cli rewards script getlogs | bash && skywire cli rewards script reward | bash ; exit 0' [Install] WantedBy=multi-user.target