diff --git a/README.md b/README.md index 973bf8d..58c8c3f 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/manifests/init.pp b/manifests/init.pp index 7cf3c1a..063602b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -14,7 +14,6 @@ $instances = {}, $workspace = '/var/puppet_db2', ) { - ensure_resource('file', $workspace, { 'ensure' => 'directory' }) create_resources('db2::install', $installations) @@ -22,5 +21,10 @@ Db2::Install<||> -> Db2::Instance<||> + exec{'db2_systemd_daemon_reload': + command => '/usr/bin/systemctl daemon-reload', + refreshonly => true, + } + } diff --git a/manifests/instance.pp b/manifests/instance.pp index 2588a24..6faa6c5 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -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, @@ -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, diff --git a/templates/db2_instance.service.erb b/templates/db2_instance.service.erb new file mode 100644 index 0000000..43c6c80 --- /dev/null +++ b/templates/db2_instance.service.erb @@ -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 +