How to get tomcat Version with the following as facter

asked 2018-01-05 12:13:37 -0600

athlonxl gravatar image

updated 2018-01-07 01:12:55 -0600

I'm trying to get my tomcat version with the following script without using version.bat or using catalina.jar. The reason being we are having issues with those at the moment as they only work when the server has been restarted which we are avoiding doing for now. below is the script im trying to use but keep getting an error saying it doesn't work. Not sure where in the script is causing me problems. tomcat_version.rb

Facter.add(:tomcat_version) do
  confine :kernel => 'windows'

setcode do 
  if version = exec { 'Tomcat_version':
  provider  => 'powershell',
  cwd       => 'c:\guidewire',
  command   => 'cat RELEASE-NOTES | find "Apache Tomcat Version"',
}
    version = version.split("\n")[20]
    version = version.split("\/")[1]
    version = version.split("\n")[0]
  else
    version = 'Tomcat not installed'
  end
end
end

The following below is the file im retriving tomcat version from

================================================================================
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
================================================================================


                     Apache Tomcat Version 8.0.45
                            Release Notes


=========
CONTENTS:
=========

* Dependency Changes
* API Stability
* Bundled APIs
* Web application reloading and static fields in shared libraries
* Security manager URLs
* Symlinking static resources
* Viewing the Tomcat Change Log
* Cryptographic software notice
* When all else fails


===================
Dependency Changes:
===================
Tomcat 8.0 is designed to run on Java SE 7 and later.


==============
API Stability:
==============

The public interfaces for the following classes are fixed and will not be
changed at all during the remaining lifetime of the 8.x series:
- All classes in the javax namespace

The public interfaces for the following classes may be added to in order to
resolve bugs and/or add new features. No existing interface method will be
removed or changed although it may be deprecated.
- org.apache.catalina.* (excluding sub-packages)

Note: As Tomcat 8 matures, the above list will be added to. The list is not
      considered complete at this time.

The remaining classes are considered part of the Tomcat internals and may change
without notice between point releases.


=============
Bundled APIs:
=============
A standard installation of Tomcat 8.0 makes all of the following APIs available
for use by web applications (by placing them in "lib"):
* annotations-api.jar (Annotations package)
* catalina.jar (Tomcat Catalina implementation)
* catalina-ant.jar (Tomcat Catalina Ant tasks)
* catalina-ha.jar (High availability package)
* catalina-storeconfig.jar (Generation of XML configuration from current state)
* catalina-tribes.jar (Group communication)
* ecj-4.6.3.jar (Eclipse JDT Java compiler)
* el-api.jar (EL 3.0 API)
* jasper.jar ...
(more)
edit retag flag offensive close merge delete

Comments

Huh, you _can_ _unpack_ `catalina.jar` and parse the file `org/apache/catalina/util/ServerInfo.properties` _without_ the requirement to start any Java. This is definitely the most clean solution, if you aren't managing the Tomcat installation via Puppet. I just have no idea how to do that in Windoze

Kai Burghardt gravatar imageKai Burghardt ( 2018-01-07 05:09:03 -0600 )edit

@Kai Burghardt Orginaly i was using java -cp lib/catalina.jar org.apache.catalina.util.ServerInfo which works but only after the server had been restarted. Which allow me to use java commands. How would i unpack the jar file without java and then parse the the file.

athlonxl gravatar imageathlonxl ( 2018-01-07 05:26:43 -0600 )edit

dest=`mktemp --directory` || exit 1; cd ${dest} || exit 2; jar xf lib/catalina.jar org/apache/catalina/util/ServerInfo.properties; grep '^server.number=' org/apache/catalina/util/ServerInfo.properties; rm --recursive --force ${dest}

Kai Burghardt gravatar imageKai Burghardt ( 2018-01-07 14:44:08 -0600 )edit

@Kai Burghardt puppet will be running on a window server so i wouldn't be able to use grep in my command. Also how would that look in my script above.

athlonxl gravatar imageathlonxl ( 2018-01-07 15:30:50 -0600 )edit

That's what I meant with “I just have no idea how to do that in Windoze” in my first comment above. My previous comment was more meant like being a PoC (proof of concept), you know.

Kai Burghardt gravatar imageKai Burghardt ( 2018-01-07 16:35:25 -0600 )edit