Introduction

  • The JS7 offers to perform any operation on orders, workflows, jobs and related objects by the JS7 - REST Web Service API.
  • The REST Web Service API can be accessed from Shell utilities such as curl.
  • In addition, a PowerShell module is available for simplified access to the REST Web Service API. This is described in the JS7 - PowerShell Module article.

The Check License Script introduced in this article can be used to check if a JS7 - License is valid or is about to expire.

License Check Script

The License Check Script is provided for download and can be used to automate checks for license expiration.

  • The script is available for Linux and MacOS® using bash shells.
  • The script terminates with exit code 0 to signal a valid license that will not expire before a number of days, with exit code 1 for command line argument errors and with exit code 4 for non-recoverable errors. Exit code 2 signals an expired license; exit code 3 signals a valid license that is about to expire within a number of days.
  • The script is intended as a baseline example for customization by JS7 users and by SOS within the scope of professional services.

Prerequisites

The Check License Script requires the jq utility to be available from the operating system. 

jq is ships with the MIT license, see https://opensource.org/licenses/MIT.

Download

Download: check-license.sh

Usage

Invoking the script without arguments displays the usage clause:


Usage
Usage: check-license.sh [Options] [Switches]

  Options:
    --url=<url>                        | required: JOC Cockpit URL, default:
    --user=<account>                   | required: JOC Cockpit user acccount
    --password=<password>              | optional: JOC Cockpit password
    --ca-cert=<path>                   | optional: path to CA Certificate used for JOC Cockpit login, default:
    --client-cert=<path>               | optional: path to Client Certificate used for login, default:
    --client-key=<path>                | optional: path to Client Key used for login, default:
    --validity-days=<number>           | optional: min. number of days for which a license should be valid, default: 60
    --log-dir=<directory>              | optional: path to the directory holding the script's batch log files, default:

  Switches:
    -h | --help                        | displays usage
    -v | --verbose                     | displays verbose output
    -p | --password                    | asks for password
    --show-logs                        | shows log output if --log-dir is used
    --make-dirs                        | creates directories if they do not exist

Options

  • --url
  • --validity-days
    • Specifies the number of days before expiration of a JS7 license.
      • Exit code 2 signals an expired license or an inapplicable license check if the Open Source License is used.
      • Exit code 3 signals a valid license that is about to expire within the number of days specified.
  • --user
    • Specifies the user account for login to JOC Cockpit. Specification of the user account can be omitted if a JS7 - Identity Services is available for Client authentication certificates that are specified with the --client-cert and --client-key options.
    • If a user account is specified then a password can be specified using the --password option or interactive keyboard input can be prompted using the -p switch.
  • --password
    • Specifies the password used for the account specified with the --user option to login to JOC Cockpit.
    • Consider use of the -p switch offering a secure option for interactive keyboard input.
  • --cacert
    • Specifies the path to a .pem file that holds the Root CA Certificate and optionally Intermediate CA Certificates to verify HTTPS connections to JOC Cockpit.
  • --client-cert
    • Specifies the path to a .pem file that holds the Client Certificate if HTTPS mutual authentication is used..
  • --client-key
    • Specifies the path to a .pem file that holds the Client Privae Key if HTTPS mutual authentication is used..
  • --log-dir
    • If a log directory is specified then the script will log information about processing steps to a log file in this directory.
    • File names are created according to the pattern: set_job_resource.<yyyy>-<MM>-<dd>T<hh>-<mm>-<ss>.log
    • For example: set_job_resource.2022-03-19T20-50-45.log

Switches

  • -h | --help
    • Displays usage.
  • -p
    • Asks the user for interactive keyboard input of the password used for the account specified with the --user option..
  • -v | --verbose
    • Displays verbose log output.
  • --show-logs
    • Displays the log output created by the script if the --log-dir option is used.
  • --make-dirs
    • If directories are missing that are indicated with the --log-dir option then they will be created.

Exit Codes

  • 0: valid license available that will not expire before the number of days specified
  • 1: argument errors
  • 2: license expired
  • 3: license is valid but is about to expire within the number of days specified
  • 4: this exit code is returned if the JS7 REST Web Service is not reachable or reports errors

Examples

The following examples illustrate typical use cases.

Check License from HTTP Connection

Example for License Check
./check-license.sh \
    --url=http://joc-2-0-primary:7446 \
    --user=root
    --password=root \
    --validity-days=60

# checks if a valid license is available that will not expire before the next 60 days

Check License from HTTPS Connection

Example for License Check
./check-license.sh \
    --url=https://joc-2-0-primary:7446 \
    --cacert=/home/sos/jstest/certs/root-ca.pem \
    --user=root \
    --validity-days=60 \
    -p
 
# checks if a valid license is available that will not expire before the next 60 days
# establishes the connection to JOC Cockpit by HTTPS and the Root CA Certificate is specified from the path to a .pem file
# asks the user for interactive keyboard input of the password used for the account specified