Skip to content

Commit 12c648d

Browse files
authored
Merge pull request #12 from thediveo/develop
fix: docsify feature: use setsid instead of woeful nohup
2 parents e55b231 + d4096b5 commit 12c648d

4 files changed

Lines changed: 41 additions & 44 deletions

File tree

src/docsify/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "docsify",
33
"id": "docsify",
4-
"version": "0.1.1",
4+
"version": "0.1.2",
55
"description": "Automatically serves ./docs workspace directory via 'docsify serve' in the background.",
66
"options": {
77
"port": {

src/docsify/fallback/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Fake Site
2+
3+
> An awesome fake site test.

src/docsify/fallback/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Fake Site</title>
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
7+
<meta name="description" content="Description">
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
9+
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
10+
</head>
11+
<body>
12+
<div id="app"></div>
13+
<script>
14+
window.$docsify = {
15+
name: 'fakesite',
16+
repo: 'fakerepo'
17+
}
18+
</script>
19+
<!-- Docsify v4 -->
20+
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
21+
</body>
22+
</html>

src/docsify/install.sh

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,19 @@
22
set -e
33

44
DOCSIFY_SERVE_PATH="/usr/local/bin/docsify-serve"
5+
DOCSIFY_FALLBACK_PATH="/usr/local/share/docsify-serve/fallback"
56

67
DOCS_PATH=${DOCS_PATH:-docs}
78

89
echo "Activating feature 'docsify-cli'..."
910

1011
npm install -g docsify-cli
1112

12-
# The fallback/default index.html file to use when the documents directory does
13-
# not exist.
14-
DEFAULT_INDEX_HTML=$(cat <<EOF
15-
<!DOCTYPE html>
16-
<html lang="en">
17-
<head>
18-
<meta charset="UTF-8">
19-
<title>Fake Site</title>
20-
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
21-
<meta name="description" content="Description">
22-
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
23-
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
24-
</head>
25-
<body>
26-
<div id="app"></div>
27-
<script>
28-
window.$docsify = {
29-
name: 'fakesite',
30-
repo: 'fakerepo'
31-
}
32-
</script>
33-
<!-- Docsify v4 -->
34-
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
35-
</body>
36-
</html>
37-
EOF
38-
)
39-
40-
# The fallback/default README.md file to use when the documents directory does
41-
# not exist.
42-
DEFAULT_README_MD=$(cat <<EOF
43-
# Fake Site
13+
mkdir -p "${DOCSIFY_FALLBACK_PATH}"
14+
cp fallback/index.html fallback/README.md "${DOCSIFY_FALLBACK_PATH}"
4415

45-
> An awesome fake site test.
46-
EOF
47-
)
48-
49-
tee "${DOCSIFY_SERVE_PATH}" > /dev/null \
50-
<< EOF
51-
#!/usr/bin/env sh
16+
cat <<EOF >"${DOCSIFY_SERVE_PATH}"
17+
#!/usr/bin/env bash
5218
5319
# we need to explicitly "activate" (the current) node here, as otherwise
5420
# devcontainers using our feature and also setting their remoteEnv PATH will
@@ -58,17 +24,23 @@ nvm use node
5824
5925
mkdir -p "${DOCS_PATH}"
6026
if [ ! -f "${DOCS_PATH}/index.html" ]; then
61-
echo "${DEFAULT_INDEX_HTML}" > "${DOCS_PATH}/index.html"
62-
echo "${DEFAULT_README_MD}" > "${DOCS_PATH}/README.md"
27+
cp ${DOCSIFY_FALLBACK_PATH}/* "${DOCS_PATH}"
6328
fi
6429
65-
nohup bash -c "\
30+
# since this script is going to be executed as this feature's
31+
# "postStartCommand" there is an important catch here: it is run via
32+
# "docker exec -it ...". Please notice the absence of "-d" as this is a
33+
# synchronous operation. Just using "nohup" as shown in several cases is
34+
# a bad idea: when postStartCommand finishes, it tears down the nohup.
35+
# Thus, use setsid(1) (https://man7.org/linux/man-pages/man1/setsid.1.html)
36+
# to run the docsify serve node process in a new session.
37+
setsid --fork bash -c "\
6638
docsify serve \
6739
-p=${PORT} \
6840
-P=${LIVERELOAD_PORT} \
6941
--no-open \
7042
${DOCS_PATH} \
71-
&" >/tmp/nohup-docsify.log 2>&1
43+
>/tmp/nohup-docsify.log 2>&1"
7244
EOF
7345

7446
chmod 0755 "${DOCSIFY_SERVE_PATH}"

0 commit comments

Comments
 (0)