-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve
executable file
·169 lines (138 loc) · 5.38 KB
/
serve
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
164
165
166
167
168
169
#!/usr/bin/env bash
ENV_FILE=".env"
# Exit on error
set -e
trap ctrl_c INT
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
function ctrl_c() {
echo "Shutting down"
echo "Killing Rails Server (puma)…"
kill $(cat ./tmp/pids/server.pid)
source 'bin/kill_delayed_jobs'
kill_delayed_jobs
kill -- -$$
}
source "scripts/bash_helpers/colors.sh"
source "scripts/bash_helpers/get_env_key.sh"
source "scripts/bash_helpers/migrations.sh"
# Make sure you've defined a host name
hostname=$(get_env_key 'HOST_NAME')
if [ -z "$hostname" ]; then
echo $RED"HOST_NAME is not set"$NOCOLOR
echo "Set it in the .env file"
echo "By default you probably want to set it to 'localhost'"
echo "ex: HOST_NAME=localhost"
echo "Check the README ways to give it a better name."
exit 78 # EX_CONFIG (78) Something was found in an unconfigured or misconfigured state.
else
echo $GREEN"HOST_NAME is set to \"$hostname\""$NOCOLOR
echo "If this is not correct please update the .env file"
echo "It will effect your ability to log in."
fi
ssh_host=$(cat $ENV_FILE | grep "^HOST_USES_SSH" | sed "s/HOST_USES_SSH=//" | sed "s/#.*//")
if [ -z "$ssh_host" ]; then
ssh_host="false"
fi
# Make sure you've defined a port (defaults in .env.sample is 3334)
port=$(get_env_key 'PORT')
if [ -z "$port" ]; then
echo $RED"PORT is not set"$NOCOLOR
echo "Set it in the .env file"
echo "By default you probably want to set it to 3334"
echo "ex: PORT=3334"
echo "Lots of development tools use 3000, so this 3334 won't interfere with them."
exit 78 # EX_CONFIG (78) Something was found in an unconfigured or misconfigured state.
else
echo $GREEN"PORT is set to \"$port\""$NOCOLOR
echo "If this is not correct please update the .env file"
fi
mongodb_url=$(get_env_key 'MONGODB_URL')
if [ -z "$mongodb_url" ]; then
echo $RED"MONGODB_URL is not set"$NOCOLOR
echo "Set it in the .env file"
echo "By default you probably want to set it to 'mongodb://localhost:27017'"
echo "ex: MONGODB_URL=mongodb://localhost:27017"
exit 78 # EX_CONFIG (78) Something was found in an unconfigured or misconfigured state.
else
echo $GREEN"MONGODB_URL is set to \"$mongodb_url\""$NOCOLOR
echo "If this is not correct please update the .env file"
fi
run_next_migration_file_if_present
search_enabled=$(get_env_key 'SEARCH_ENABLED')
if [ -z "$search_enabled" ]; then
echo $RED"SEARCH_ENABLED is not set"$NOCOLOR
echo "Search will be unavailable"
echo "Set it to true in the .env file to enable search"
echo "ex: SEARCH_ENABLED=true"
elif [ "$search_enabled" == "true" ]; then
set +e # don't exit on error because meilisearch may not be running
# Test if meilisearch is running
pgrep -x meilisearch > /dev/null
meili_status=$?
#Start it if it isn't.
if [ $meili_status -ne 0 ]; then
echo $GREEN"booting Meilisearch too..."$NOCOLOR
meili_master_key=$(get_env_key 'MEILI_MASTER_KEY')
if [ -z "$meili_master_key" ]; then
echo $RED"MEILI_MASTER_KEY is not set"$NOCOLOR
echo "You can run the following to generate a usable key:"
echo "openssl rand -base64 32 | sed 's/=$//'"
echo "Store that in your .env file where noted."
echo "start it by running `meilisearch` with no arguments"
exit 78 # EX_CONFIG (78) Something was found in an unconfigured or misconfigured state.
fi
meilisearch_search_key=$(get_env_key 'MEILISEARCH_SEARCH_KEY')
if [ -z "$meilisearch_search_key" ]; then
echo "⚠️ MEILISEARCH_SEARCH_KEY not found in .env"
echo "⚠️ PLEASE ADD MEILISEARCH_SEARCH_KEY to .env to improve security"
echo " See Getting Started instructions for details."
else
echo "✅ MEILISEARCH_SEARCH_KEY found in .env Good for you!"
fi
meilisearch_admin_key=$(get_env_key 'MEILISEARCH_ADMIN_KEY')
if [ -z "$meilisearch_admin_key" ]; then
echo "⚠️ MEILISEARCH_ADMIN_KEY not found in .env"
echo "⚠️ PLEASE ADD MEILISEARCH_ADMIN_KEY to .env to improve security"
echo " See Getting Started instructions for details."
else
echo "✅ MEILISEARCH_ADMIN_KEY found in .env Good for you!"
fi
meilisearch --master-key "$meili_master_key" > /dev/null 2>&1 &
meilisearch_status=$?
if [ $meilisearch_status -ne 0 ]; then
echo $RED"Meilisearch failed to start"$NOCOLOR
echo $RED"Search will be unavailable"$NOCOLOR
echo "Check the output above for more information"
fi
disown
else
echo $GREEN"Meilisearch is already running"$NOCOLOR
fi
set -e
else
echo $YELLOW"Search is disabled via .env"$NOCOLOR
fi
worker_count=$(get_env_key 'DELAYED_JOB_WORKERS')
if [ -z "$worker_count" ]; then
echo $YELLOW"DELAYED_JOB_WORKERS is not set"$NOCOLOR
echo "Will use 2 workers by default."
echo "Configure this as an integer in your .env file"
worker_count=2
else
echo $GREEN"DELAYED_JOB_WORKERS is set to \"$worker_count\""$NOCOLOR
echo "If this is not correct please update the .env file"
fi
echo "Starting $worker_count Delayed Job Workers"
# Start the Delayed Job Workers
bin/delayed_job -n $worker_count start & disown
if [ "$ssh_host" == "false" ]; then
visitable_url="http://$hostname:$port"
else
visitable_url="https://$hostname"
fi
echo $GREEN"VISIT YOUR BACKUP BRAIN AT $visitable_url"$NOCOLOR
# Start Rails
# bundle exec rails server -p $port -u puma
bundle exec rails server -u puma
#TODO nothing in delayed_job_pids
#TODO maybe background the rails server too?