-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathrun
More file actions
executable file
·76 lines (68 loc) · 2.22 KB
/
run
File metadata and controls
executable file
·76 lines (68 loc) · 2.22 KB
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
#!/usr/bin/env bash
set -e # Exit on any command failure
if [ $# -eq 0 ]; then
echo 'Please inform the app name. ex: "./run chain-indexer"'
exit 1
fi
# Check if the argument ends with -api or -indexer
if [[ "$1" == *-api ]] || [[ "$1" == *-indexer ]]; then
# Standard case: start the specific service
echo -e "\n-->> Starting $1..."
(
set -x
pm2 start pm2/ecosystem.config.cjs --only "$@" --update-env
)
echo -e "\n-->> Saving pm2 state..."
(
set -x
pm2 save
)
echo -e "\n-->> Reading $1 logs..."
(
set -x
pm2 logs --raw --lines 10 "$@"
)
else
# Chain name without suffix: start both indexer and api
echo -e "\n-->> Starting $1-indexer and $1-api..."
(
set -x
pm2 start pm2/ecosystem.config.cjs --only "$1-indexer" --update-env
pm2 start pm2/ecosystem.config.cjs --only "$1-api" --update-env
)
echo -e "\n-->> Saving pm2 state..."
(
set -x
pm2 save
)
echo -e "\n-->> Creating tmux session with split logs for $1..."
# Check if tmux session already exists, kill it if it does
if tmux has-session -t "$1-logs" 2>/dev/null; then
echo -e "\n-->> Tmux session '$1-logs' already exists. Killing it..."
tmux kill-session -t "$1-logs"
fi
# Create new tmux session with split panes
tmux new-session -d -s "$1-logs" -n "logs"
tmux split-window -h -t "$1-logs:logs"
# Send commands to each pane
tmux send-keys -t "$1-logs:logs.0" "pm2 logs --raw $1-indexer" C-m
tmux send-keys -t "$1-logs:logs.1" "pm2 logs --raw $1-api" C-m
# Set pane titles
tmux select-pane -t "$1-logs:logs.0" -T "$1-indexer"
tmux select-pane -t "$1-logs:logs.1" -T "$1-api"
echo -e "\n-->> Tmux session '$1-logs' created with split logs"
echo -e " Left pane: $1-indexer logs"
echo -e " Right pane: $1-api logs"
echo -e "\n-->> To attach: tmux attach -t $1-logs"
echo -e " To detach: Ctrl+b then d"
echo -e " To kill session: tmux kill-session -t $1-logs"
# Prompt user to attach
echo -e "\n-->> Would you like to attach to the tmux session now? (y/N)"
read -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
tmux attach -t "$1-logs"
else
echo -e "Session running in background. Use 'tmux attach -t $1-logs' to view logs."
fi
fi