tomcat_service

May 7, 2026 ยท View on GitHub

Manages a Tomcat instance as a systemd service.

Actions

ActionDescription
:createCreates the systemd unit. Default action.
:startCreates and starts the systemd unit.
:stopStops the systemd unit.
:restartRestarts the systemd unit.
:enableCreates and enables the systemd unit.
:disableDisables the systemd unit.
:deleteStops, disables, and deletes the systemd unit.

Properties

PropertyTypeDefaultDescription
instance_nameStringname propertyTomcat instance name.
install_pathString/opt/tomcat_INSTANCETomcat install or symlink path.
tomcat_userStringtomcat_INSTANCEUser the service runs as.
tomcat_groupStringtomcat_INSTANCEGroup the service runs as.
service_nameStringtomcat_INSTANCEsystemd service name without .service.
env_varsArrayCATALINA_PID=$CATALINA_BASE/bin/tomcat.pidEnvironment entries for the unit.
service_varsArray[]Additional systemd [Service] directives.
unit_contentHash, String, nilnilFull custom systemd unit content.

Examples

Start And Enable

tomcat_service 'default' do
  action [:enable, :start]
end

Custom Environment

tomcat_service 'app' do
  install_path '/opt/tomcat_app'
  env_vars [
    { 'CATALINA_BASE' => '/opt/tomcat_app' },
    { 'CATALINA_PID' => '/opt/tomcat_app/bin/tomcat.pid' },
    { 'JAVA_OPTS' => '-Xms512m -Xmx512m' },
  ]
  action [:enable, :start]
end

Custom Unit Content

tomcat_service 'app' do
  unit_content(
    Unit: {
      Description: 'Custom Tomcat',
      After: 'network.target',
    },
    Service: {
      Type: 'forking',
      ExecStart: '/opt/tomcat_app/bin/catalina.sh start',
      ExecStop: '/opt/tomcat_app/bin/catalina.sh stop',
      User: 'tomcat_app',
      Group: 'tomcat_app',
    },
    Install: {
      WantedBy: 'multi-user.target',
    }
  )
end