Skip to content
Browse files

Updated to use configuration instead of options. Works better with la…

…test moonshine.
  • Loading branch information...
1 parent d02c76e commit 46081f46e73c987bdfbb7eea49345c6a8feeb90d @jnunemaker jnunemaker committed Dec 17, 2010
Showing with 50 additions and 55 deletions.
  1. +9 −10 lib/mongodb.rb
  2. +41 −45 templates/mongo.init.erb
View
19 lib/mongodb.rb
@@ -39,13 +39,12 @@ def mongodb(hash = {})
options = {
:version => '1.4.4',
- :master => false,
- :auth => false,
- :slave_enabled => false,
- :slave => {
+ :master? => false,
+ :auth => false,
+ :slave? => false,
+ :slave => {
:auto_resync => false,
- :source_master => '',
- :source_port => 27017
+ :master_host => ''
}
}.merge(hash)
@@ -77,9 +76,10 @@ def mongodb(hash = {})
]
file '/etc/init.d/mongodb',
- :mode => '744',
- :content => template(File.join(File.dirname(__FILE__), '..', 'templates', 'mongo.init.erb'), binding),
- :before => service('mongodb')
+ :mode => '744',
+ :content => template(File.join(File.dirname(__FILE__), '..', 'templates', 'mongo.init.erb'), binding),
+ :before => service('mongodb'),
+ :checksum => :md5
service "mongodb",
:ensure => :running,
@@ -90,5 +90,4 @@ def mongodb(hash = {})
exec('install_mongodb')
]
end
-
end
View
86 templates/mongo.init.erb
@@ -28,26 +28,26 @@
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: An object/document-oriented database
-# Description: MongoDB is a high-performance, open source, schema-free
+# Description: MongoDB is a high-performance, open source, schema-free
# document-oriented data store that's easy to deploy, manage
# and use. It's network accessible, written in C++ and offers
# the following features:
-#
+#
# * Collection oriented storage - easy storage of object-
# style data
# * Full index support, including on inner objects
# * Query profiling
# * Replication and fail-over support
-# * Efficient storage of binary data including large
+# * Efficient storage of binary data including large
# objects (e.g. videos)
# * Auto-sharding for cloud-level scalability (Q209)
-#
+#
# High performance, scalability, and reasonable depth of
# functionality are the goals for the project.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-DAEMON=/opt/local/mongo-<%= options[:version] %>/bin/mongod
+DAEMON=/opt/local/mongo-<%= configuration[:mongodb][:version] %>/bin/mongod
DATA=/data/db
NAME=MongoDB
DESC=database
@@ -71,27 +71,23 @@ DIETIME=10 # Time to wait for the server to die, in seconds
# let some servers to die gracefully and
# 'restart' will not work
-LOGFILE=$LOGDIR/$NAME.log # Server logfile
DAEMON_OPTS="--dbpath $DATA run"
-<% if options[:master] %>
+<% if configuration[:mongodb][:master?] %>
DAEMON_OPTS="--master $DAEMON_OPTS"
<% end %>
-
-<% if options[:auth] %>
+<% if configuration[:mongodb][:auth] %>
DAEMON_OPTS="--auth $DAEMON_OPTS"
<% end %>
-
-<% if options[:slave_enabled] %>
- <% if options[:slave][:auto_resync] %>
+<% if configuration[:mongodb][:slave?] %>
+ <% if configuration[:mongodb][:slave][:auto_resync] %>
DAEMON_OPTS="--autoresync $DAEMON_OPTS"
<% end %>
- DAEMON_OPTS="--source <%= options[:slave][:source_master] %>:<%= options[:slave][:source_port] %>"
+ DAEMON_OPTS="--slave --source <%= configuration[:mongodb][:slave][:master_host] %> $DAEMON_OPTS"
<% end %>
-
# Include mongodb defaults if available
if [ -f /etc/default/$NAME ] ; then
- . /etc/default/$NAME
+ . /etc/default/$NAME
fi
# DAEMONUSER=mongodb
@@ -107,7 +103,7 @@ fi
# exit 1
# fi
# fi
-#
+#
# set -e
@@ -147,7 +143,7 @@ start_server() {
--exec $DAEMON -- $DAEMON_OPTS
errcode=$?
fi
- return $errcode
+ return $errcode
}
stop_server() {
@@ -164,7 +160,7 @@ stop_server() {
errcode=$?
fi
- return $errcode
+ return $errcode
}
reload_server() {
@@ -177,27 +173,27 @@ reload_server() {
force_stop() {
# Force the process to die killing it manually
- [ ! -e "$PIDFILE" ] && return
- if running ; then
- kill -15 $pid
- # Is it really dead?
- sleep "$DIETIME"s
- if running ; then
- kill -9 $pid
- sleep "$DIETIME"s
- if running ; then
- echo "Cannot kill $NAME (pid=$pid)!"
- exit 1
- fi
- fi
- fi
- rm -f $PIDFILE
+ [ ! -e "$PIDFILE" ] && return
+ if running ; then
+ kill -15 $pid
+ # Is it really dead?
+ sleep "$DIETIME"s
+ if running ; then
+ kill -9 $pid
+ sleep "$DIETIME"s
+ if running ; then
+ echo "Cannot kill $NAME (pid=$pid)!"
+ exit 1
+ fi
+ fi
+ fi
+ rm -f $PIDFILE
}
case "$1" in
start)
- log_daemon_msg "Starting $DESC $NAME"
+ log_daemon_msg "Starting $DESC $NAME"
# Check if it's running first
if running ; then
log_progress_msg "apparently already running"
@@ -208,7 +204,7 @@ case "$1" in
# NOTE: Some servers might die some time after they start,
# this code will detect this issue if STARTTIME is set
# to a reasonable value
- [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time
+ [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time
if running ; then
# It's ok, the server started and is running
log_end_msg 0
@@ -220,12 +216,12 @@ case "$1" in
# Either we could not start it
log_end_msg 1
fi
- ;;
+ ;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
if running ; then
# Only stop the server if we see it running
- errcode=0
+ errcode=0
stop_server || errcode=$?
log_end_msg $errcode
else
@@ -241,22 +237,22 @@ case "$1" in
if running; then
# If it's still running try to kill it more forcefully
log_daemon_msg "Stopping (force) $DESC" "$NAME"
- errcode=0
+ errcode=0
force_stop || errcode=$?
log_end_msg $errcode
fi
- ;;
+ ;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
- errcode=0
+ errcode=0
stop_server || errcode=$?
# Wait some sensible amount, some server need this
[ -n "$DIETIME" ] && sleep $DIETIME
start_server || errcode=$?
[ -n "$STARTTIME" ] && sleep $STARTTIME
running || errcode=$?
log_end_msg $errcode
- ;;
+ ;;
status)
log_daemon_msg "Checking status of $DESC" "$NAME"
@@ -300,10 +296,10 @@ case "$1" in
#;;
*)
- N=/etc/init.d/$NAME
- echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
- exit 1
- ;;
+ N=/etc/init.d/$NAME
+ echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
+ exit 1
+ ;;
esac
exit 0

0 comments on commit 46081f4

Please sign in to comment.
Something went wrong with that request. Please try again.