Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
appwrite/mongo-entrypoint.sh at main · appwrite/appwrite · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
appwrite
appwrite
Repository navigation
Code
Issues
356
(356)
Pull requests
473
(473)
Discussions
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
appwrite
/
mongo-entrypoint.sh
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
79 lines (65 loc) · 2.67 KB
main
Breadcrumbs
appwrite
/
mongo-entrypoint.sh
Copy path
Top
File metadata and controls
Code
Blame
79 lines (65 loc) · 2.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!
/bin/bash
set
-e
#
Fix keyfile permissions if mounted from volume
KEYFILE_PATH=
"
/data/keyfile/mongo-keyfile
"
if
[
!
-f
"
$KEYFILE_PATH
"
]
;
then
echo
"
Generating random MongoDB keyfile...
"
mkdir -p /data/keyfile
openssl rand -base64 756
>
"
$KEYFILE_PATH
"
fi
chmod 400
"
$KEYFILE_PATH
"
chown mongodb:mongodb
"
$KEYFILE_PATH
"
2>
/dev/null
||
chown 999:999
"
$KEYFILE_PATH
"
#
The standard entrypoint initialises an empty data directory with a second mongod
#
on 27017, stopped with `mongod --shutdown`. That returns once the server clears
#
<dbpath>/mongod.lock, several steps before it exits and releases the port, and
#
the real server binds a millisecond after it starts -- so a slow shutdown tail
#
leaves it exiting 48, "Address already in use", taking the container with it.
#
Initialise here instead, on a port the real server never binds, and hand over a
#
directory the standard entrypoint has nothing left to do to.
#
#
The marker is written only once every user exists, because mongod creates the
#
data directory long before that: keying off the directory would let a first boot
#
interrupted midway come back up with authentication on and no one to authenticate
#
as. Each step below is skippable, so a resumed initialisation finishes the part
#
that did not happen.
INIT_MARKER=/data/db/.appwrite-initialised
if
[
!
-e
"
$INIT_MARKER
"
]
;
then
INIT_PORT=27018
echo
"
Initialising MongoDB data directory...
"
find -L /data/db
\!
-user mongodb -exec chown mongodb
'
{}
'
+
export
MONGO_INITDB_DATABASE=
"
${MONGO_INITDB_DATABASE
:-
test}
"
gosu mongodb mongod --dbpath /data/db --bind_ip 127.0.0.1 --port
"
$INIT_PORT
"
&
INIT_SERVER=
$!
READY=
for
_
in
$(
seq 1 30
)
;
do
if
mongosh --host 127.0.0.1 --port
"
$INIT_PORT
"
--quiet --eval
'
quit(0)
'
>
/dev/null
2>&1
;
then
READY=1
break
fi
if
!
kill
-0
"
$INIT_SERVER
"
2>
/dev/null
;
then
break
fi
sleep 1
done
if
[
-z
"
$READY
"
]
;
then
echo
"
MongoDB did not accept connections for initialisation
"
>&2
exit
1
fi
mongosh --host 127.0.0.1 --port
"
$INIT_PORT
"
--quiet admin --eval
'
const username = process.env.MONGO_INITDB_ROOT_USERNAME;
if (db.getUser(username) === null) {
db.createUser({
user: username,
pwd: process.env.MONGO_INITDB_ROOT_PASSWORD,
roles: [{ role: "root", db: "admin" }]
});
}
'
mongosh --host 127.0.0.1 --port
"
$INIT_PORT
"
--quiet
"
$MONGO_INITDB_DATABASE
"
/mongo-init.js
touch
"
$INIT_MARKER
"
kill
-TERM
"
$INIT_SERVER
"
wait
"
$INIT_SERVER
"
echo
"
MongoDB data directory initialised.
"
fi
#
Use MongoDB's standard entrypoint with our command
exec
docker-entrypoint.sh mongod --replSet rs0 --bind_ip_all --auth --keyFile
"
$KEYFILE_PATH
"
You can’t perform that action at this time.