Skip to content

Commit

Permalink
fix embedded scripts and update systemd service template
Browse files Browse the repository at this point in the history
  • Loading branch information
0pcom committed Oct 23, 2024
1 parent 151006e commit 3eeeb5a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 37 deletions.
6 changes: 5 additions & 1 deletion cmd/skywire-cli/commands/rewards/getlogs.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 11 additions & 9 deletions cmd/skywire-cli/commands/rewards/reward.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
59 changes: 32 additions & 27 deletions cmd/skywire-cli/commands/rewards/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3eeeb5a

Please sign in to comment.