Defined Type: usertomcat::instance

Defined in:
manifests/instance.pp

Overview

Create a new user and tomcat-home and add tomcat-user-instance uses debian package tomcat7-user

Parameters:

  • gid (Any) (defaults to: undef)

    the group id of new user

  • uid (Any) (defaults to: undef)

    the user id of new user

  • http_port (Any)

    which port should tomcat listen on

  • control_port (Any)

    the tomcat control port

  • jmx_port (Any) (defaults to: undef)

    port for java jmx management, defaults to undef, in which case no jmx port will be openend

  • xmx (Any) (defaults to: '128m')

    java max memory allocation (Xmx), default: 128m

  • xms (Any) (defaults to: '32m')

    java inital memory allocation (Xms), default: 32m

  • user (Any) (defaults to: $name)

    user which the service belongs to (will be created), defaults to $name if not set

  • group (Any) (defaults to: $name)

    usergroup which the service belongs to (will be created), defaults to $name if not set

  • additional_java_opts (Any) (defaults to: undef)

    additional opts to be passed to tomcat as JAVA_OPTS

  • init_dependencies (Any) (defaults to: undef)

    services which should be started before this tomcat, added as dependency to init.d script, separate with whitespace if more than one

  • collectd_enabled (Any) (defaults to: false)

    collect stats with collect, needs jmx_port to be set

  • tomcat_version (Any) (defaults to: '7')


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'manifests/instance.pp', line 40

define usertomcat::instance (
  $http_port,
  $control_port,
  $gid                  = undef,
  $uid                  = undef,
  $jmx_port             = undef,
  $xmx                  = '128m',
  $xms                  = '32m',
  $group                = $name,
  $user                 = $name,
  $tomcat_version       = '7',
  $additional_java_opts = undef,
  $init_dependencies    = undef,
  $collectd_enabled     = false,
) {

  require 'usertomcat::dependencies'

  ensure_packages(["tomcat${tomcat_version}", "tomcat${tomcat_version}-user", 'libtcnative-1'])

  # Check if group and user are already existing.
  # Just in case we have two tomcats using the same user and group
  # (e.g. tgcrud and tgcrud-public or group ULSB is already existing :-)
  if ! defined(Group[$group]) {
    group { $group:
      ensure =>  present,
      gid    =>  $gid,
    }
  }
  if ! defined(User[$user]) {
    user { $user:
      ensure     => present,
      uid        => $uid,
      gid        => $gid,
      shell      => '/bin/bash',
      home       => "/home/${user}",
      managehome => true,
    }
  }

  exec { "create_${name}":
    path    => ['/usr/bin','/bin','/usr/sbin'],
    command => "tomcat${tomcat_version}-instance-create -p ${http_port} -c ${control_port} /home/${user}/${name}",
    creates => "/home/${user}/${name}",
    user    => $user,
    require => Package["tomcat${tomcat_version}-user"],
  }
  ~>
  exec { "patching_${name}_for_apr":
    path        => ['/usr/bin','/bin','/usr/sbin'],
    command     => "patch /home/${user}/${name}/conf/server.xml < /usr/local/src/tomcat${tomcat_version}-apr.patch",
    refreshonly => true,
    require     => File["/usr/local/src/tomcat${tomcat_version}-apr.patch"],
  }

  file { "/etc/init.d/${name}":
    ensure  => file,
    content => template("usertomcat/etc/init.d/tomcat${tomcat_version}.Debian.erb"),
    owner   => 'root',
    group   => 'root',
    mode    => '0755',
    before  => Service[$name],
    notify  => Service[$name],
  }

  file { "/etc/default/${name}":
    ensure  => file,
    content => template("usertomcat/etc/default/tomcat${tomcat_version}.erb"),
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    before  => Service[$name],
    notify  => Service[$name],
  }

  file {"/var/log/${name}":
    ensure => link,
    target => "/home/${user}/${name}/logs",
  }

  service { $name:
    ensure  => running,
    enable  => true,
    require => Exec["create_${name}"],
  }

  logrotate::rule { $name:
    path         => "/home/${user}/${name}/logs/catalina.out",
    require      => Exec["create_${name}"],
    rotate       => 365,
    rotate_every => 'week',
    compress     => true,
    copytruncate => true,
    missingok    => true,
    ifempty      => true,
    dateext      => true,
    dateformat   => '.%Y-%m-%d',
  }

  if $collectd_enabled {
    collectd::plugin::genericjmx::connection { $name:
      host            => $facts['networking']['fqdn'],
      service_url     => "service:jmx:rmi:///jndi/rmi://localhost:${jmx_port}/jmxrmi",
      collect         => [ 'memory-heap', 'memory-nonheap', 'process_cpu_load' ],
      instance_prefix => "${name}-",
    }
  }

}