-
Notifications
You must be signed in to change notification settings - Fork 14
/
start.sh
executable file
·136 lines (115 loc) · 3.67 KB
/
start.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# https://stackoverflow.com/questions/2379829/while-loop-to-test-if-a-file-exists-in-bash
cantonPortFile="./canton-sandbox-port.txt"
jsonApiPortFile="./json-api-port.txt"
# After 20 seconds the loop will exit
timeout=20
rmCantonPortFile(){
echo "Checking canton port file"
if [ -f "$cantonPortFile" ]; then
rm "$cantonPortFile"
echo "Removed canton port file"
fi
echo "Checking server port file"
if [ -f "$jsonApiPortFile" ]; then
rm "$jsonApiPortFile"
echo "Removed canton port file"
fi
}
runSandbox(){
daml sandbox --dar main/Asset/asset.dar --dar main/User/user.dar --dar main/Account/account.dar --port-file ${cantonPortFile}
}
startJsonApiServer(){
echo "Starting Json api server"
daml json-api --config json-api-app.conf
}
waitForSandBox(){
while [ ! -f "$cantonPortFile" ];
do
echo "Setting up sandbox..."
if [ "$timeout" == 0 ]; then
echo "ERROR: Timeout while waiting for the file ${cantonPortFile}"
exit 1
sleep 2 # or less like 0.2
fi
sleep 1
((timeout--))
done
echo "Canton sandBox setup complete"
}
waitForServer(){
while [ ! -f "$jsonApiPortFile" ];
do
echo "WAITING FOR SERVER"
if [ "$timeout" == 0 ]; then
echo "ERROR: Timeout while waiting for server file."
exit 1
sleep 2 # or less like 0.2
fi
sleep 5
((timeout--))
done
echo "Triggers Running"
}
addParties(){
echo "Adding Parties"
daml script --dar ./main/Setup/setup.dar --script-name Setup:setup --ledger-host localhost --ledger-port 6865
echo "Parties added"
}
startSendAssetHoldingAccountInviteTrigger(){
echo "Starting Trigger 1"
daml trigger --dar triggers/triggers.dar \
--trigger-name SendAssetHoldingAccountInviteTrigger:sendAssetHoldingAccountInviteTrigger \
--ledger-host localhost \
--ledger-port 6865 \
--ledger-user "admin"
}
startAcceptAirdropRequestTrigger(){
echo "Starting Trigger 2"
daml trigger --dar triggers/triggers.dar \
--trigger-name AcceptAirdropRequestTrigger:acceptAirdropRequestTrigger \
--ledger-host localhost \
--ledger-port 6865 \
--ledger-user "admin"
}
startAcceptAssetInviteTrigger(){
echo "Starting Trigger 3"
daml trigger --dar triggers/triggers.dar \
--trigger-name AcceptAssetInviteTrigger:acceptAssetInviteTrigger \
--ledger-host localhost \
--ledger-port 6865 \
--ledger-user "admin"
}
startAcceptSwapTrigger(){
echo "Starting Trigger 4"
daml trigger --dar triggers/triggers.dar \
--trigger-name AcceptSwapTrigger:acceptSwapTrigger \
--ledger-host localhost \
--ledger-port 6865 \
--ledger-user "admin"
}
cleanup() {
echo "cleaning up..."
rmCantonPortFile
# Our cleanup code goes here
}
startTriggers(){
echo "Starting triggers"
startSendAssetHoldingAccountInviteTrigger &
startAcceptAirdropRequestTrigger &
startAcceptSwapTrigger &
startAcceptAssetInviteTrigger &
}
# trap "echo signal received!" SIGINT
trap 'trap " " SIGTERM; kill 0; wait; cleanup;' SIGINT SIGTERM
rmCantonPortFile &&
(runSandbox & waitForSandBox) && addParties &&
(startJsonApiServer & waitForServer ) &&
(startSendAssetHoldingAccountInviteTrigger &
startAcceptAirdropRequestTrigger &
startAcceptSwapTrigger &
startAcceptAssetInviteTrigger) &
wait
# Check if process is running, run the below:
# ps aux | grep "daml json"
# https://superuser.com/questions/1653229/when-pressed-ctrlc-only-break-out-of-current-function-and-not-whole-bash-script
# https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script