Skip to content

Commit

Permalink
Merge pull request #23 from zephirworks/master
Browse files Browse the repository at this point in the history
Add FreeBSD support.
  • Loading branch information
tobami committed Mar 14, 2012
2 parents 97cf337 + 20f93d7 commit 54cf5d9
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 5 deletions.
11 changes: 11 additions & 0 deletions mongodb/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,14 @@
default[:mongodb][:shard_name] = "default"

default[:mongodb][:enable_rest] = false

case node['platform']
when "freebsd"
default[:mongodb][:defaults_dir] = "/etc/rc.conf.d"
default[:mongodb][:init_dir] = "/usr/local/etc/rc.d"
default[:mongodb][:root_group] = "wheel"
else
default[:mongodb][:defaults_dir] = "/etc/default"
default[:mongodb][:init_dir] = "/etc/init.d"
default[:mongodb][:root_group] = "root"
end
8 changes: 4 additions & 4 deletions mongodb/definitions/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@
end

# default file
template "/etc/default/#{name}" do
template "#{node['mongodb']['defaults_dir']}/#{name}" do
action :create
source "mongodb.default.erb"
group "root"
group node['mongodb']['root_group']
owner "root"
mode "0644"
variables(
Expand Down Expand Up @@ -126,10 +126,10 @@
end

# init script
template "/etc/init.d/#{name}" do
template "#{node['mongodb']['init_dir']}/#{name}" do
action :create
source "mongodb.init.erb"
group "root"
group node['mongodb']['root_group']
owner "root"
mode "0755"
variables :provides => name
Expand Down
2 changes: 1 addition & 1 deletion mongodb/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

depends "apt"

%w{ ubuntu debian }.each do |os|
%w{ ubuntu debian freebsd }.each do |os|
supports os
end

Expand Down
24 changes: 24 additions & 0 deletions mongodb/templates/freebsd/mongodb.default.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This config file is auto-generated by chef
# please don't modify manually

DAEMON_OPTS="--fork"

<%= @port ? "DAEMON_OPTS=\"$DAEMON_OPTS --port #{@port}\"" : "" %>
<%= @dbpath ? "DAEMON_OPTS=\"$DAEMON_OPTS --dbpath #{@dbpath}\"" : "" %>
<%= @logpath ? "DAEMON_OPTS=\"$DAEMON_OPTS --logpath #{@logpath}\"" : "" %>
<%= @config ? "DAEMON_OPTS=\"$DAEMON_OPTS --config #{@config}\"" : "" %>
<%= @configdb ? "DAEMON_OPTS=\"$DAEMON_OPTS --configdb #{@configdb}\"" : "" %>
<%= @configsrv ? "DAEMON_OPTS=\"$DAEMON_OPTS --configsvr\"" : "" %>
<%= @shardsrv ? "DAEMON_OPTS=\"$DAEMON_OPTS --shardsvr\"" : "" %>
<% if @replicaset_name %>
DAEMON_OPTS="$DAEMON_OPTS --replSet <%= @replicaset_name %>"
<% end %>
<% if @enable_rest %>
DAEMON_OPTS="$DAEMON_OPTS --rest"
<% end %>
<%= @name %>_command_args="$DAEMON_OPTS"
45 changes: 45 additions & 0 deletions mongodb/templates/freebsd/mongodb.init.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh

# PROVIDE: <%= @provides %>
# REQUIRE: NETWORK
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# <%= @provides %>_enable (bool): Set to NO by default.
# Set it to YES to enable mongod.
#
# Additional configurable variables:
# <%= @provides %>_config (path): Set to /usr/local/etc/mongodb.conf
# by default. Additional configuration. You
# can also use mongod_flags for additional
# command line arguments.
# <%= @provides %>_dbpath (path): Set to /var/db/mongodb by default
# <%= @provides %>_user (username): Set to "mongodb" by default

. /etc/rc.subr

name="<%= @provides %>"
rcvar=${name}_enable

command=/usr/local/bin/mongod

load_rc_config $name

: ${<%= @provides %>_enable="NO"}
: ${<%= @provides %>_config="/usr/local/etc/mongodb.conf"}
: ${<%= @provides %>_dbpath="/var/db/mongodb"}
: ${<%= @provides %>_user="mongodb"}
: ${<%= @provides %>_command_args=""}

if [ "x$<%= @provides %>_command_args" = "x" ]
then
command_args="-f $<%= @provides %>_config --dbpath $<%= @provides %>_dbpath --logappend --logpath $<%= @provides %>_dbpath/<%= @provides %>.log --fork"
else
command_args="$<%= @provides %>_command_args"
fi

required_dirs=${<%= @provides %>_dbpath}

run_rc_command "$1"

0 comments on commit 54cf5d9

Please sign in to comment.