Skip to content

Commit

Permalink
Separate mongodb.pp. Script generation moved to mongodb_script.pp. In…
Browse files Browse the repository at this point in the history
…tegrate server process operation with server_process.cpp. fixes #4518
  • Loading branch information
Masahiro Nakagawa committed Jun 20, 2011
1 parent 3ad4748 commit 3935dfc
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 84 deletions.
113 changes: 29 additions & 84 deletions manifests/mongodb.pp
Original file line number Diff line number Diff line change
@@ -1,101 +1,46 @@
# sedue::mongodb assumes sedue::supervise already called

define sedue::mongodb($user, $instance, $port, $pair, $run) {
define sedue::mongodb($user, $instance, $port, $pair, $run) {
if $run {
$server_sleep_interval = 3
$server_name = 'mongodb'
$server_type = 'db'
$server_script_name = $server_name

if $pair {
$mongodb_options = "--port ${port} --nohttpinterface --oplogSize 4096 --master --slave --source ${pair} --autoresync --quiet"
} else {
$mongodb_options = "--port ${port} --nohttpinterface --quiet"
}

file { "sedue::${instance}_mongodb_directory_repos":
file { "sedue::${instance}::mongodb::directory_repos":
path => "${sedue_home}/repos/${instance}",
owner => $user,
group => $user,
mode => '0755',
ensure => 'directory'
}

# generate files for serve supervise
file { "sedue::${instance}_mongodb_run_file":
path => "${sedue_home}/etc/serve/${instance}/mongodb.run",
owner => $user,
group => $user,
mode => '0755',
content => template("sedue/mongodb.run.erb"),
require => File["${instance}_serve_directory"]
}

file { "sedue::${instance}_mongodb_run_directory":
path => "${sedue_home}/etc/serve/${instance}/mongodb",
owner => $user,
group => $user,
mode => '0755',
ensure => 'directory',
require => File["${instance}_serve_directory"]
}

file { "sedue::${instance}_mongodb_run_symlink":
path => "${sedue_home}/etc/serve/${instance}/mongodb/run",
ensure => 'link',
target => "${sedue_home}/etc/serve/${instance}/mongodb.run",
require => [File["sedue::${instance}_mongodb_run_file"], File["sedue::${instance}_mongodb_run_directory"]]
# generate script and then run it
sedue::mongodb_script { "sedue::${instance}::mongodb::script":
user => $user,
instance => $instance,
port => $port,
pair => $pair,
run => $run,
require => File["sedue::${instance}::mongodb::directory_repos"]
}

file { "sedue::${instance}_mongodb_init_script":
path => "${sedue_home}/etc/init.d/mongodb-${instance}",
owner => $user,
group => $user,
mode => '0755',
content => template("sedue/server.init.d.erb")
}

service { "sedue::${instance}_mongodb_process":
path => "${sedue_home}/etc/init.d/",
name => "mongodb-${instance}",
ensure => 'running',
hasstatus => 'true', # this need to be true
provider => 'init',
require => File["sedue::${instance}_mongodb_init_script"]
sedue::server_process { "sedue::${instance}::mongodb::process":
instance => $instance,
server_type => 'mongodb',
run => $run,
require => Sedue::Mongodb_script["sedue::${instance}::mongodb::script"]
}
} else {
service { "sedue::${instance}_mongodb_process":
path => "${sedue_home}/etc/init.d/",
name => "mongodb-${instance}",
ensure => 'stopped',
hasstatus => 'true', # this need to be true
provider => 'init'
}

file { "sedue::${instance}_mongodb_init_script":
path => "${sedue_home}/etc/init.d/mongodb-${instance}",
ensure => 'absent',
require => Service["sedue::${instance}_mongodb_process"]
}

# remove all unnecessary files
file { "sedue::${instance}_mongodb_run_symlink":
path => "${sedue_home}/etc/serve/${instance}/mongodb/run",
ensure => 'absent',
require => File["${instance}_serve_directory"]
}

file { "sedue::${instance}_mongodb_run_directory":
path => "${sedue_home}/etc/serve/${instance}/mongodb",
ensure => 'absent',
force => true, # to remove dir/control, dir/stat
require => File["sedue::${instance}_mongodb_run_symlink"]
}

file { "sedue::${instance}_mongodb_run_file":
path => "${sedue_home}/etc/serve/${instance}/mongodb.run",
ensure => 'absent',
require => File["sedue::${instance}_mongodb_run_directory"]
# stop process and then delete script
sedue::server_process { "sedue::${instance}::mongodb::process":
instance => $instance,
server_type => 'mongodb',
run => $run
}

sedue::mongodb_script { "sedue::${instance}::mongodb::script":
user => $user,
instance => $instance,
port => $port,
pair => $pair,
run => $run,
require => Sedue::Server_process["sedue::${instance}::mongodb::process"]
}
}
}
75 changes: 75 additions & 0 deletions manifests/mongodb_script.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# sedue::mongodb assumes sedue::supervise already called

define sedue::mongodb_script($user, $instance, $port, $pair, $run) {
if $run {
$server_sleep_interval = 3
$server_name = 'mongodb'
$server_type = 'db'
$server_script_name = $server_name

if $pair {
$mongodb_options = "--port ${port} --nohttpinterface --oplogSize 4096 --master --slave --source ${pair} --autoresync --quiet"
} else {
$mongodb_options = "--port ${port} --nohttpinterface --quiet"
}

# generate files for serve supervise
file { "sedue::${instance}::mongodb::run_file":
path => "${sedue_home}/etc/serve/${instance}/mongodb.run",
owner => $user,
group => $user,
mode => '0755',
content => template("sedue/mongodb.run.erb"),
require => File["${instance}_serve_directory"]
}

file { "sedue::${instance}::mongodb::run_directory":
path => "${sedue_home}/etc/serve/${instance}/mongodb",
owner => $user,
group => $user,
mode => '0755',
ensure => 'directory',
require => File["${instance}_serve_directory"]
}

file { "sedue::${instance}::mongodb::run_symlink":
path => "${sedue_home}/etc/serve/${instance}/mongodb/run",
ensure => 'link',
target => "${sedue_home}/etc/serve/${instance}/mongodb.run",
require => [File["sedue::${instance}::mongodb::run_file"], File["sedue::${instance}::mongodb::run_directory"]]
}

file { "sedue::${instance}::mongodb::init_script":
path => "${sedue_home}/etc/init.d/mongodb-${instance}",
owner => $user,
group => $user,
mode => '0755',
content => template("sedue/server.init.d.erb")
}
} else {
# remove all unnecessary files
file { "sedue::${instance}::mongodb::run_symlink":
path => "${sedue_home}/etc/serve/${instance}/mongodb/run",
ensure => 'absent',
require => File["${instance}_serve_directory"]
}

file { "sedue::${instance}::mongodb::run_directory":
path => "${sedue_home}/etc/serve/${instance}/mongodb",
ensure => 'absent',
force => true, # to remove dir/control, dir/stat
require => File["sedue::${instance}::mongodb::run_symlink"]
}

file { "sedue::${instance}::mongodb::run_file":
path => "${sedue_home}/etc/serve/${instance}/mongodb.run",
ensure => 'absent',
require => File["sedue::${instance}::mongodb::run_directory"]
}

file { "sedue::${instance}::mongodb::init_script":
path => "${sedue_home}/etc/init.d/mongodb-${instance}",
ensure => 'absent',
}
}
}
4 changes: 4 additions & 0 deletions manifests/server_process.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
$server_bin_name = 'sedue-assist-server'
$server_script_name = 'sedue-assist-server'
}
'mongodb': {
$server_bin_name = 'mongodb'
$server_script_name = 'mongodb'
}
}

if $run {
Expand Down

0 comments on commit 3935dfc

Please sign in to comment.