-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mongodb,redis: refine startup script
- Loading branch information
1 parent
5272386
commit 4876231
Showing
6 changed files
with
80 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,26 @@ FROM packageman/base:1.0.1 | |
|
||
MAINTAINER Byron Zhang <[email protected]> | ||
|
||
ENV MONGO_VERSION ${MONGO_VERSION:-3.2.7} | ||
|
||
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 \ | ||
&& echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" > /etc/apt/sources.list.d/mongodb-org.list\ | ||
&& apt-get update \ | ||
&& DEBIAN_FRONTEND="noninteractive" apt-get install -y \ | ||
mongodb-org=3.2.7 \ | ||
mongodb-org-server=3.2.7 \ | ||
mongodb-org-shell=3.2.7 \ | ||
mongodb-org-mongos=3.2.7 \ | ||
mongodb-org-tools=3.2.7 --no-install-recommends | ||
mongodb-org=${MONGO_VERSION} \ | ||
mongodb-org-server=${MONGO_VERSION} \ | ||
mongodb-org-shell=${MONGO_VERSION} \ | ||
mongodb-org-mongos=${MONGO_VERSION} \ | ||
mongodb-org-tools=${MONGO_VERSION} --no-install-recommends | ||
|
||
ADD mongod.conf /etc/mongod.conf | ||
|
||
RUN mkdir -p /etc/service/mongodb | ||
ADD start.sh /etc/service/mongodb/run | ||
RUN chmod +x /etc/service/mongodb/run | ||
|
||
EXPOSE 27017 | ||
|
||
VOLUME /var/lib/mongodb | ||
VOLUME ["/var/log/mongodb", "/var/lib/mongodb"] | ||
|
||
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# mongod.conf | ||
|
||
# for documentation of all options, see: | ||
# http://docs.mongodb.org/manual/reference/configuration-options/ | ||
|
||
storage: | ||
dbPath: /var/lib/mongodb | ||
journal: | ||
enabled: true | ||
|
||
systemLog: | ||
destination: file | ||
logAppend: true | ||
logRotate: reopen | ||
path: /var/log/mongodb/mongod.log | ||
|
||
net: | ||
port: 27017 | ||
bindIp: 0.0.0.0 | ||
|
||
security: | ||
authorization: enabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,28 @@ | ||
#!/bin/bash | ||
#! /bin/bash | ||
|
||
/sbin/setuser mongodb mongod --dbpath /var/lib/mongodb --bind_ip 0.0.0.0 | ||
set -e | ||
exec 2>&1 | ||
|
||
pidFile=/tmp/mongod.pid | ||
configFile=/etc/mongod.conf | ||
userInitializedFile=/tmp/mongoUserInitialized | ||
|
||
function init_mongo_user { | ||
/sbin/setuser mongodb mongod -f /etc/mongod.conf --noauth --pidfilepath $pidFile --fork | ||
|
||
username=${MONGO_USERNAME:-"admin"} | ||
password=${MONGO_USERNAME:-"Abc123__"} | ||
|
||
echo "db.createUser({user: '${username}', pwd: '${password}', roles: ['root']})" | mongo admin | ||
echo "username: $username, password: $password, role: root" > $userInitializedFile | ||
|
||
kill -2 `cat $pidFile` | ||
rm $pidFile | ||
} | ||
|
||
|
||
if [[ $INIT_MONGO_USER ]] && [[ ! -f $userInitializedFile ]]; then | ||
init_mongo_user | ||
fi | ||
|
||
/sbin/setuser mongodb mongod -f /etc/mongod.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
daemonize no | ||
|
||
port 6379 | ||
|
||
bind 0.0.0.0 | ||
|
||
logfile /var/log/redis/redis.log | ||
|
||
dir /var/lib/redis | ||
|
||
dbfilename dump.rdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
#!/bin/bash | ||
|
||
if [ $PASS ]; then | ||
echo "requirepass $PASS" >> /etc/redis/redis.conf | ||
set -e | ||
exec 2>&1 | ||
|
||
configFile=/etc/redis/redis.conf | ||
|
||
if [ $REDIS_PASSWORD ]; then | ||
echo "requirepass $REDIS_PASSWORD" >> $configFile | ||
fi | ||
|
||
service redis-server start | ||
/sbin/setuser redis redis-server $configFile |