-
Notifications
You must be signed in to change notification settings - Fork 2
/
runme.sh
executable file
·163 lines (136 loc) · 4.78 KB
/
runme.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
#FILE=/data/runcomplete
#if [ -f "$FILE" ]; then
# echo "First run already performed"
#else
# echo "Performing first run now"
# cp -rn /dataorig/. /data/
# cd /datacore-bot/src/DataCore.CLI/
# echo "Training behold images"
# dotnet run train
# echo "Training complete"
# cd /asset-server/
# echo "First run complete, next time, please run with XXXXX at the end of your docker command"
#fi
##################################################
# Configuring PM2 #
##################################################
echo "Configuring PM2"
source /data/config/env
pm2 install pm2-discord-webhook
# Don't forward stdout - too spammy
pm2 set pm2-discord-webhook:log false
# Do forward stderr - useful
pm2 set pm2-discord-webhook:error true
# Send messages when service starts or restarts
pm2 set pm2-discord-webhook:start true
pm2 set pm2-discord-webhook:online true
pm2 set pm2-discord-webhook:stop true
pm2 set pm2-discord-webhook:restart true
# Set destinations for webhooks (URLs sourced from env)
pm2 set pm2-discord-webhook:webhook_url_logs ${PM2_INFO_URL}
pm2 set pm2-discord-webhook:webhook_url_errors ${PM2_ERROR_URL}
##################################################
# Setting up static website content #
##################################################
# Check if the attached data folder contains website data, if not create the folder
if [ ! -d /data/website ]
then
echo "Website folder doesn't exist in your data folder, creating it."
mkdir /data/website
fi
# If the /website symlink doesn't exist, create it. Not sure it will ever exist...
if [ ! -d /website ]
then
echo "Linking your website data folder into place"
ln -s /data/website /website
fi
# If the git config isn't there, check the folder is empty, then clone the repo and build it
if [ ! -f /website/.git/config ]
then
if [ ! "$(ls -A /website)" ]
then
echo "Cloning website repository"
git clone https://github.com/stt-datacore/website.git /website
echo "Linking env to website"
ln -s /data/config/env /website/.env
echo "Building website, this may take some time"
/website/publish.sh -f
else
echo "'website' folder in your data area is not empty, and does not appear to contain the git repo for the website."
echo "Please clean it up and start again"
exit 1
fi
fi
##################################################
# Start site server #
##################################################
echo "Starting site server"
if [ ! -f /site-server/.env ]
then
ln -s /data/config/env /site-server/.env
fi
if [ ! -d /data/profiles ]
then
echo "Creating a folder to store profiles in, as you don't seem to have one"
mkdir /data/profiles
fi
if [ ! -d /site-server/static ]
then
ln -s /data/profiles /site-server/static
fi
cd /site-server
pm2 --name server start npm -- start
##################################################
# Start discord bot #
##################################################
echo "Starting bot"
if [ ! -f /bot/.env ]
then
ln -s /data/config/env /bot/.env
fi
cd /bot
pm2 --name bot start npm -- start
##################################################
# Run asset server updates #
##################################################
if [ ! -d /data/asset-server ]
then
echo "Website folder doesn't exist in your data folder, creating it."
mkdir /data/asset-server
fi
if [ ! -L /asset-server/out ]
then
echo "Linking asset server in"
mv /asset-server/out/* /data/asset-server
rm -rf /asset-server/out
ln -s /data/asset-server /asset-server/out
fi
if [ ! -L /asset-server/build/out ]
then
echo "Linking asset server in"
ln -s /data/asset-server /asset-server/build/out
fi
echo "Downloading assets. This will take a couple of hours on the first run"
/asset-server/exec.sh
##################################################
# Start remaining services and crontab #
##################################################
echo "Copy crontab in"
crontab -i /data/config/crontab
echo "Starting nginx"
service nginx start
echo "Starting cron"
service cron start
##################################################
# Start image analysis server #
##################################################
if [ ! -d /data/train ]
then
echo "Behold training data folder does not exist, creating it."
mkdir /data/train
fi
echo "Starting image analysis server. Training will take some time before analysis can take place"
cd /cpp-image-analysis/build
pm2 start "./imserver --jsonpath=/website/public_web/structured/ --trainpath=/data/train/ --datapath=/cpp-image-analysis/data/ --asseturl=https://assets.datacore.app/" --name "imageAnalysis"
pm2 logs