First released in version: 3.8.1

Passing Configuration Files to Services

The following example shows how you can build multiple services, each using a copy of the same executable, with a configuration file that specializes it to each service's requirements.

Requirements

Requires SmartSpace 3.8 SP1 or later

How it Works

If a service definition in a package XML file includes a single (and only a single) library file with the architecture 'common', the service controller can copy this file to the execution directory of the service and the name of this file will be passed to the service executable on the command line as the third argument (after the arguments that specify cell type and cell ID).

Example

The example shows how a single executable, ubisense_service_config_example.exe, can be installed and run as three different services each of which uses a separate configuration file.

The source files (Windows only) for the example are provided in package.zip. If you want to work through the instructions step by step, download and unzip the files to a suitable location, i.e. where you can access them with your Service Manager application.

Files and File Structure

package.zip contains the following files and directories:

The package directory contains the package service definition for "Example Package" in ConfigExample.xml, shown below.

<install>
   <vendor>Ubisense</vendor>
   <package>Example Package</package>
   <services>
      <value>
         <name>Example service 1</name>
         <version><major_>1</major_><minor_>0</minor_><build_>0</build_></version>
         <level>Site</level>
         <programs>
             <key>i586_windows_1.3</key>
             <value>ubisense_service_config_example.exe</value>
         </programs>
         <libraries>
            <key>common</key>
            <value>
               <value>config1.txt</value>
            </value>
         </libraries>
         <data>
         </data>
      </value>
      <value>
         <name>Example service 2</name>
         <version><major_>1</major_><minor_>0</minor_><build_>0</build_></version>
         <level>Site</level>
         <programs>
             <key>i586_windows_1.3</key>
             <value>ubisense_service_config_example.exe</value>
         </programs>
         <libraries>
            <key>common</key>
            <value>
               <value>config2.txt</value>
            </value>
         </libraries>
         <data>
         </data>
      </value>
      <value>
         <name>Example service 3</name>
         <version><major_>1</major_><minor_>0</minor_><build_>0</build_></version>
         <level>Site</level>
         <programs>
             <key>i586_windows_1.3</key>
             <value>ubisense_service_config_example.exe</value>
         </programs>
         <libraries>
            <key>common</key>
            <value>
               <value>config3.txt</value>
            </value>
         </libraries>
         <data>
         </data>
      </value>
   </services>
</install>

In the common directory are the configuration files for the different services and the executable is in i586_windows_1.3.

Also included in package.zip is cxx_src_for_example.cc, the source code for the executable.

Installing the Example Services

  1. In Service Manager, click Install services....

  2. Browse to the folder containing the package service definition and ensure that Everything (no feature dependencies) found is selected.

    Service Manager showing example packages selected for installation

  3. Select Deploy services to deploy the services immediately they are installed, and click Install.

  4. When the installation process is complete, click Finish. Back in the main Service Manager window, opening Services > Ubisense and dragging Example Package into the filter shows the status of the new services to be Running:

    Service Manager showing three example services running

    Similarly, running the ubisense_service_admin will show the services are running:

    $ ./ubisense_service_admin.exe status Example
    Service                                    Version  Cell  Controller                    Desired Actual   Last Backup
    Ubisense:Example Package:Example service 1 v1.0.0   Site  RXXXXXXS-T460S.ubisense.local Running Running  Thu Apr  6 11:48:52 2023
    Ubisense:Example Package:Example service 2 v1.0.0   Site  RXXXXXXS-T460S.ubisense.local Running Running  Thu Apr  6 11:48:52 2023
    Ubisense:Example Package:Example service 3 v1.0.0   Site  RXXXXXXS-T460S.ubisense.local Running Running  Thu Apr  6 11:48:52 2023

Trace Messages

With the services installed, the trace shows the example up and running.

[05/04/2023 14:52:27] warning: controller loaded files for Example Package/Example service 1 V1.0.0 on "Site"
[05/04/2023 14:52:27] warning: controller loaded files for Example Package/Example service 2 V1.0.0 on "Site"
[05/04/2023 14:52:27] warning: controller loaded files for Example Package/Example service 3 V1.0.0 on "Site"
[05/04/2023 14:52:29] warning: controller started process for Example Package/Example service 1 V1.0.0 on "Site"
[05/04/2023 14:52:29] warning: command line = ubisense_service_config_example.exe UCell::Cell 04007zZDn2e3uD6u000H8000002 config1.txt
[05/04/2023 14:52:29] warning: EXAMPLE CONFIGURATION SERVICE
[05/04/2023 14:52:29] warning: argv[0] = ".\ubisense_service_config_example.exe"
[05/04/2023 14:52:29] warning: argv[1] = "UCell::Cell"
[05/04/2023 14:52:29] warning: argv[2] = "04007zZDn2e3uD6u000H8000002"
[05/04/2023 14:52:29] warning: argv[3] = "config1.txt"
[05/04/2023 14:52:29] warning: USING config1.txt AS CONFIG FILE
[05/04/2023 14:52:29] warning: config1.txt: Line 1
[05/04/2023 14:52:29] warning: config1.txt: Line 2
[05/04/2023 14:52:29] warning: config1.txt: Line 3
[05/04/2023 14:52:29] warning: controller started process for Example Package/Example service 2 V1.0.0 on "Site"
[05/04/2023 14:52:29] warning: command line = ubisense_service_config_example.exe UCell::Cell 04007zZDn2e3uD6u000H8000002 config2.txt
[05/04/2023 14:52:29] warning: EXAMPLE CONFIGURATION SERVICE
[05/04/2023 14:52:29] warning: argv[0] = ".\ubisense_service_config_example.exe"
[05/04/2023 14:52:29] warning: argv[1] = "UCell::Cell"
[05/04/2023 14:52:29] warning: argv[2] = "04007zZDn2e3uD6u000H8000002"
[05/04/2023 14:52:29] warning: argv[3] = "config2.txt"
[05/04/2023 14:52:29] warning: USING config2.txt AS CONFIG FILE
[05/04/2023 14:52:29] warning: config2.txt: Line 1
[05/04/2023 14:52:29] warning: config2.txt: Line 2
[05/04/2023 14:52:29] warning: config2.txt: Line 3
[05/04/2023 14:52:29] warning: config2.txt: Line 4
[05/04/2023 14:52:29] warning: config2.txt: Line 5
[05/04/2023 14:52:29] warning: controller started process for Example Package/Example service 3 V1.0.0 on "Site"
[05/04/2023 14:52:29] warning: command line = ubisense_service_config_example.exe UCell::Cell 04007zZDn2e3uD6u000H8000002 config3.txt
[05/04/2023 14:52:29] warning: EXAMPLE CONFIGURATION SERVICE
[05/04/2023 14:52:29] warning: argv[0] = ".\ubisense_service_config_example.exe"
[05/04/2023 14:52:29] warning: argv[1] = "UCell::Cell"
[05/04/2023 14:52:29] warning: argv[2] = "04007zZDn2e3uD6u000H8000002"
[05/04/2023 14:52:29] warning: argv[3] = "config3.txt"
[05/04/2023 14:52:29] warning: USING config3.txt AS CONFIG FILE
[05/04/2023 14:52:29] warning: config3.txt: Line 1
[05/04/2023 14:52:29] warning: config3.txt: Line 2
[05/04/2023 14:52:29] warning: config3.txt: Line 3
[05/04/2023 14:52:29] warning: config3.txt: Line 4
[05/04/2023 14:52:29] warning: config3.txt: Line 5
[05/04/2023 14:52:29] warning: config3.txt: Line 6
[05/04/2023 14:52:29] warning: config3.txt: Line 7