generated from opentensor/bittensor-subnet-template
-
Notifications
You must be signed in to change notification settings - Fork 43
/
run.sh
executable file
·99 lines (84 loc) · 2.29 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
# Initialize variables
script="neurons/validator.py"
autoRunLoc=$(readlink -f "$0")
proc_name="s1_validator_main_process"
update_proc_name="check_updates"
args=()
version_location="./prompting/__init__.py"
version="__version__"
old_args=$@
# Check if pm2 is installed
if ! command -v pm2 &> /dev/null
then
echo "pm2 could not be found. Please run the install.sh script first."
exit 1
fi
# Uninstall uvloop
poetry run pip uninstall -y uvloop
# Loop through all command line arguments
while [[ $# -gt 0 ]]; do
arg="$1"
# Check if the argument starts with a hyphen (flag)
if [[ "$arg" == -* ]]; then
# Check if the argument has a value
if [[ $# -gt 1 && "$2" != -* ]]; then
if [[ "$arg" == "--script" ]]; then
script="$2";
shift 2
else
# Add '=' sign between flag and value
args+=("'$arg'");
args+=("'$2'");
shift 2
fi
else
# Add '=True' for flags with no value
args+=("'$arg'");
shift
fi
else
# Argument is not a flag, add it as it is
args+=("'$arg '");
shift
fi
done
# Check if script is already running with pm2
if pm2 status | grep -q $proc_name; then
echo "The main is already running with pm2. Stopping and restarting..."
pm2 delete $proc_name
fi
# Check if the update check is already running with pm2
if pm2 status | grep -q $update_proc_name; then
echo "The update check is already running with pm2. Stopping and restarting..."
pm2 delete $update_proc_name
fi
# Run the Python script with the arguments using pm2
echo "Running $script with the following pm2 config:"
# Join the arguments with commas using printf
joined_args=$(printf "%s," "${args[@]}")
# Remove the trailing comma
joined_args=${joined_args%,}
# Create the pm2 config file
echo "module.exports = {
apps: [
{
name: '$proc_name',
script: 'poetry',
interpreter: 'python3',
min_uptime: '5m',
max_restarts: '5',
args: ['run', 'python', '$script', $joined_args]
},
{
name: 'check_updates',
script: './scripts/check_updates.sh',
interpreter: '/bin/bash',
min_uptime: '5m',
max_restarts: '5'
}
]
};" > app.config.js
# Print configuration to be used
cat app.config.js
pm2 start app.config.js