@@ -154,25 +154,47 @@ INT_PORT=$(comm -23 <(seq $(cat /proc/sys/net/ipv4/ip_local_port_range | tr ' '
154
154
<( netstat -ntl | awk ' /LISTEN/ {split($4,a,":"); print a[2]}' | sort -u) 2> /dev/null \
155
155
| shuf | head -n 1)
156
156
157
+ wait_for_process_logfile() {
158
+ local name=\$ 1
159
+ local file=\$ 2
160
+ local now=\$ (date +%s)
161
+ local end=\$ ((now + 5))
162
+ while true; do
163
+ if [ -s "\$ {file}" ]; then
164
+ echo "...\$ {name} started"
165
+ break
166
+ fi
167
+ now=\$ (date +%s)
168
+ if [ "\$ {now}" -ge "\$ {end}" ]; then
169
+ echo "ERROR: \$ {name} did not start"
170
+ break
171
+ fi
172
+ sleep 0.25
173
+ done
174
+ }
175
+
157
176
# Start browser-sync in the background to proxy from the local pkgsite on a
158
177
# random/ephemeral HTTP port that the determined above to the "public" port
159
178
# where browser want to connect to.
160
- nohup bash -c "\
179
+ BROWSYNC_LOGFILE=/tmp/nohup-local-pkgsite-browser-sync.log
180
+ setsid --fork bash -c "\
161
181
browser-sync start \
162
182
--port ${PORT} \
163
183
--proxy localhost:\$ {INT_PORT} \
164
184
--reload-delay ${RELOAD_DELAY} \
165
185
--reload-debounce ${RELOAD_DEBOUNCE} \
166
186
--no-ui \
167
187
--no-open \
168
- " >/tmp/nohup-local-pkgsite-browser-sync.log 2>&1 &
188
+ >\$ {BROWSYNC_LOGFILE} 2>&1"
189
+ wait_for_process_logfile "browser-sync" \$ {BROWSYNC_LOGFILE}
169
190
170
191
# Monitor for any *.go or (heaven forbid) our go.mod to change, then first
171
192
# terminate the already running local pkgsite and restart it; as before, serve
172
193
# the local pkgsite on a random/ephemeral HTTP port that the determined above.
173
194
# Then trigger a reload in connected browsers. Please note that we run nodemon
174
- # and it will then run "browser-sync reload" on demand, as well as ).
175
- nohup bash -c "\
195
+ # and it will then run "browser-sync reload" on demand, as well as pkgsite).
196
+ NODEM_LOGFILE=/tmp/nohup-local-pkgsite-nodemon.log
197
+ setsid --fork bash -c "\
176
198
nodemon \
177
199
--signal SIGTERM \
178
200
--watch './**/*' \
@@ -182,7 +204,8 @@ nohup bash -c "\
182
204
browser-sync --port ${PORT} reload \
183
205
&& ${PKGSITE_BIN} -http=localhost:\$ {INT_PORT} .
184
206
\" \
185
- &" >/tmp/nohup-local-pkgsite-nodemon.log 2>&1
207
+ >\$ {NODEM_LOGFILE} 2>&1"
208
+ wait_for_process_logfile "nodemon" \$ {NODEM_LOGFILE}
186
209
EOF
187
210
chmod 0755 " ${PKGSITE_SERVE_PATH} "
188
211
0 commit comments