Examples on using service objects

The following services are written with UNIX style path separator characters, except where otherwise stated.

Using a server service object

This example shows how to define, use, and alter, a server service object to start a trigger monitor.

  1. A server service object is defined, using the following MQSC command:
    DEFINE SERVICE(S1) +
           CONTROL(QMGR) +
           SERVTYPE(SERVER) +
           STARTCMD('+MQ_INSTALL_PATH+/bin/runqmtrm') +
           STARTARG('-m +QMNAME+ -i ACCOUNTS.INITIATION.QUEUE')
           STOPCMD('+MQ_INSTALL_PATH+/bin/amqsstop') +
           STOPARG('-m +QMNAME+ -p +MQ_SERVER_PID')
    Where:
  2. An instance of the server service object will execute when the queue manager is nest started. However, we will start an instance of the server service object immediately with the following MQSC command:
    START SERVICE(S1)
  3. The status of the server service process is displayed, using the following MQSC command:
    DISPLAY SVSTATUS(S1)
  4. This example now shows how to alter the server service object and have the updates picked up by manually restarting the server service process. The server service object is altered so that the initiation queue is specified as JUPITER.INITIATION.QUEUE. The following MQSC command is used:
    ALTER SERVICE(S1) +
          STARTARG('-m +QMNAME+ -i JUPITER.INITIATION.QUEUE')
    Note:
    A running service will not pick up any updates to its service definition until it is restarted.
  5. The server service process is restarted so that the alteration is picked up, using the following MQSC commands:
    STOP SERVICE(S1)
    Followed by:
    START SERVICE(S1)
    The server service process is restarted and picks up the alterations made in 4.
    Note:
    The MQSC command, STOP SERVICE, can only be used if a STOPCMD argument is specified in the service definition.

Using a command service object

This example shows how to define a command service object to start a program that writes entries to the operating system's system log when a queue manager is started or stopped:

  1. The command service object is defined, using the following MQSC command:
    DEFINE SERVICE(S2) +
           CONTROL(QMGR) +
           SERVTYPE(COMMAND) +
           STARTCMD('/usr/bin/logger') +
           STARTARG('Queue manager +QMNAME+ starting') +
           STOPCMD('/usr/bin/logger') +
           STOPARG('Queue manager +QMNAME+ stopping')
    Where:

Using a command service object when a queue manager ends only

This example shows how to define a command service object to start a program that writes entries to the operating system's system log when a queue manager is stopped only:

  1. The command service object is defined, using the following MQSC command:
    DEFINE SERVICE(S3) +
           CONTROL(QMGR) +
           SERVTYPE(COMMAND) +
           STOPCMD('user/bin/logger') +
           STOPARG('Queue manager +QMNAME+ stopping')
    Where:

More on passing arguments

This example is written with Windows style path separator characters.

This example shows how to define a server service object to start a program called runserv when a queue manager is started. One of the arguments that is to be passed to the starting program is a string containing a space. This argument needs to be passed as a single string. To achieve this, double quotes are used as shown in the following command to define the command service object:

  1. The server service object is defined, using the following MQSC command:
       DEFINE SERVICE(S1) SERVTYPE(SERVER) CONTROL(QMGR)
         STARTCMD('C:\Program Files\Tools\runserv.exe')
         STARTARG('-m +QMNAME+ -d "C:\Program Files\Tools\"') 
         STDOUT('C:\Program Files\Tools\+MQ_SERVICE_NAME+.out')
    
    
    DEFINE SERVICE(S4) +
           CONTROL(QMGR) +
           SERVTYPE(SERVER) +
           STARTCMD('C:\Program Files\Tools\runserv.exe') +
           STARTARG('-m +QMNAME+ -d "C:\Program Files\Tools\"') +
           STDOUT('C:\Program Files\Tools\+MQ_SERVICE_NAME+.out')
    
    Where: