Skip to content

Feature/manage instance service #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ db2::install { '11.1':
* `instance_user_uid`: UID of the instance user
* `instance_user_gid`: GID of the instance user
* `instance_user_home`: Home directory of the instance user
* `manage_service`: Whether or not to manage the service for the instance (default: false)
* `service_enable`: If the service is managed, whether or not it should be registered for startup on server start (default: true)
* `service_ensure`: If the service is managed, whether or not puppet should make sure it is running (default: undef)
* `type`: Type of product this instance is for (default: ese)
* `auth`: Type of auth for this instance (default: server)
* `users_forcelocal`: Force the creation of instance and fence users to be local, true or false. (default: undef)
Expand Down
6 changes: 5 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
$instances = {},
$workspace = '/var/puppet_db2',
) {

ensure_resource('file', $workspace, { 'ensure' => 'directory' })

create_resources('db2::install', $installations)
create_resources('db2::instance', $instances)

Db2::Install<||> -> Db2::Instance<||>

exec{'db2_systemd_daemon_reload':
command => '/usr/bin/systemctl daemon-reload',
refreshonly => true,
}

}

34 changes: 34 additions & 0 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
$instance_user = $name,
$manage_fence_user = true,
$manage_instance_user = true,
$manage_service = false,
$service_ensure = undef,
$service_enable = true,
$fence_user_uid = undef,
$fence_user_gid = undef,
$fence_user_home = undef,
Expand Down Expand Up @@ -46,6 +49,37 @@
}
}

if $manage_service {
if $instance_user_home == undef{
fail('Please set instance_user_home in order to manage the db2 service instance')
}

$instance_service = "db2_${name}.service"

file{"/etc/systemd/system/${instance_service}":
ensure => present,
content => template('db2/db2_instance.service.erb'),
owner => 'root',
group => 'root',
mode => '0644',
notify => Exec['db2_systemd_daemon_reload'],
}

service{$instance_service:
ensure => $service_ensure,
enable => $service_enable,
subscribe => [
Exec['db2_systemd_daemon_reload'],
Db2_instance[$instance_user],
],
require => [
Db2_catalog_node[keys($catalog_nodes)],
Db2_catalog_database[keys($catalog_databases)],
Db2_catalog_dcs[keys($catalog_dcs)],
],
}
}

db2_instance { $instance_user:
install_root => $installation_root,
fence_user => $fence_user,
Expand Down
23 changes: 23 additions & 0 deletions templates/db2_instance.service.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[Unit]
Description=DB2 Database Instance <%= @name %>
After=network.target

[Service]
Type=forking
User=<%= @instance_user_uid || @instance_user %>
<%- if @instance_user_gid -%>
Group=<%= @instance_user_gid %>
<%- end -%>
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=db2
ExecStart=<%= File.join(@instance_user_home, 'sqllib/adm/db2start') %>
ExecStop=<%= File.join(@instance_user_home, 'sqllib/adm/db2stop') %>
Environment="DB2INSTANCE=<%= @name %>"
Environment="DB2LIB=<%= File.join(@instance_user_home, 'sqllib/lib') %>"
Environment="DB2_HOME=<%= File.join(@instance_user_home, 'sqllib') %>"
Restart=always

[Install]
WantedBy=multi-user.target