Running Programs at Start-up Time

From CometWiki

Revision as of 10:06, 26 May 2009 by Badge (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Running Programs at Startup Time

This document describes how to automatically start programs when Comet starts up. This feature is typically used to start one or more programs that will continue to run while Comet is running, such as:

Using “forever mode” to unspool print jobs from the Comet Print Spooler 
Starting the XAPMON feature on an eComet system 
Activating a system-monitoring program in a background partition in order to shut down the Comet node at a certain time of day 
These and other start-up applications are very easy to implement. In fact, the instructions can be stated in two sentences: 

Create an Internet Basic program that runs, enters, or activates the desired program(s) and name the object program QSTARTX. Place QSTARTX on any configured directory except the Comet release directories (REL, UTL, CED, etc.).

When you launch Comet, the QSTART program (located in the REL directory) searches through the accessed directories for a program named QSTARTX. If such a program is found, it executes in the node’s first partition. This occurs before CMONITOR and QMONITOR are run for the first time. Thus, you have the ability to write a custom start-up program for your Comet system.

Here are some examples:

Example 1

Suppose you want to start XAPMON at start-up time on an eComet system. XAPMON, the program that opens and monitors the XAP gateway, can be run as a program (from the READY prompt) or subprogram (using the ENTER statement in an Internet Basic program). To automate the process of running this program at start-up, you can write a one-line QSTARTX program that enters XAPMON. Here’s the code:

!S XQSTARTX,MSC
!O QSTARTX,MSC
!L TXX,E
!R CED
!
ENTER "XAPMON"
END

Note that the above code simply enters XAPMON without verifying the node name or other criteria. In a multi-node network, it's likely that XAPMON will be run on one node only (the eComet node), and you would therefore need to add extra code to QSTARTX to make sure it enters XAPMON on just the desired node.

Example 2

Suppose you want to start the spooler's “forever mode” each time you launch a Comet node. You can accomplish this by creating a command file for the spooler and writing a QSTARTX program to run the QSPOOL program in command mode. Here are the steps:

  • a. Use the Comet Editor (CED) to create a spooler command file. For purposes of this example, we will name this command file STARTSPL. The command file format is:

spool-name,printer,partition,delete-flag,forever-flag,pause-parameter,skip-flag

For example, to start SP1 on LP1, running in partition P12, deleting jobs after they're printed, running in forever mode (and not closing the printer between jobs), waiting 20 seconds before checking for new jobs, and skipping incomplete jobs, you would write the following line in the command file:

SP1,LP1,P12,D,FO,20,S

For additional spooler starts (SP2, for example), include additional lines in the command file.

  • b. Next, create a QSTARTX program that runs QSPOOL and sends it the command file name in COMMON. Here’s the code:
!S XQSTARTX,MSC
!O QSTARTX,MSC
!L TXX,E
!R CED
!
LENGTH 8 & COMMON CmdFile$          ! To store the command file name
CmdFile$ = "STARTSPL"               ! The command file name
RUN "QSPOOL"                        ! Run the spooler in command mode
END

When you start Comet, QSTARTX runs QSPOOL in command mode and passes it the command file name (STARTSPL) in COMMON. QSPOOL processes the command file, which activates “forever mode” in a background partition.

As with the previous example, you would need to add code to QSTARTX to handle the specific needs of a multi-node Comet network (where each node would typically have unique printer/spooler names and partition numbers).

Example 3

Suppose you want to automatically start a program that monitors the system clock and shuts down the Comet node at a certain time each day (as part of an automated backup scheme for your network). You can accomplish this by writing a “shutdown” program that gets activated by your QSTARTX program.

a. Here’s the “shutdown” program:

!========================================================================================
!     S E T   S T A T E M E N T S
!=========================================================================================
      SET ShutdownTime$ = "23:00"              ! When to shutdown
      SET Seconds = 30                         ! Number of seconds to pause
!=========================================================================================
!     D A T A   S E C T I O N
!=========================================================================================
      LENGTH 80 & LOCAL A$
      LENGTH 6.0 & LOCAL PauseTime
!=======================================================================================
!     C O D E   S E C T I O N
!=========================================================================================
      PauseTime = Seconds * 18                        ! Calculate the pause factor
      DO                                              ! Start loop
             A$ = DSTAT("CL1")                         ! Refresh TIME$
             IF TIME$ > ShutdownTime$ THEN BREAK      ! See if it's time to shutdown
             PAUSE PauseTime                          ! Wait before checking again
      LOOP                                            ! Continue looping
      ! The program gets to this section when TIME$ is greater than the ShutdownTime$
      ! Find the first partition number on this node and convert 
      ! the number to a partition name
      A$ = DSTAT("X00")             
      A$ = STRIP(STR(HEXDEC(SUB(A$,50,1)+SUB(A$,49,1)))) 
      KILL A$                    ! Kill any program running in first partition
      PAUSE 90                   ! Wait 5 seconds for QMONITOR to setup MESSAGESUB
      MESSAGE$ = 'QIPL0'         ! Use MESSAGE$ to tell QMONITOR to run QIPL0
      INTERRUPT A$               ! Interrupt the first partition and shutdown the node
 END

There are two main sections in the logic of this program. The first section is the DO loop that refreshes TIME$ and checks to see if TIME$ exceeds the specified shutdown time (in this example, the shutdown time may be specified as any time before midnight). If the shutdown time has not been reached, the program pauses for a specified amount of time (in the above example, it’s 30 seconds) and then checks again.

When TIME$ exceeds the specified shutdown time, the program branches to the second section. The program determines the number of the first partition on the node (by using the DSTAT function on “X00”), kills any program running in that partition, pauses for 5 seconds (in order for QMONITOR to start running), sets MESSAGE$ to “QIPL0” and performs an INTERRUPT on the first partition. These steps cause QMONITOR to run “QIPL0” in the first partition of the node, which shuts down Comet on that node.

The above program is available in the download/demos area.

b. Here’s the QSTARTX program that activates the “shutdown” program:

!S XQSTARTX,MSC
!O QSTARTX,MSC
!L TXX,E
!R CED
!
ACTIVATE "","SHUTDOWN"
END

Example 4

Finally, here’s an example that shows how multiple events can be included in the QSTARTX program. In this example, we activate the “shutdown” program and then start the unspooling process.

!S XQSTARTX,MSC
!O QSTARTX,MSC
!L TXX,E
!R CED
LENGTH 8 & COMMON CmdFile$          ! To store the command file name
ACTIVATE "","SHUTDOWN"              ! Activate the shutdown program
CmdFile$ = "STARTSPL"               ! The command file name
RUN "QSPOOL"                        ! Run the spooler in command mode
END

Summary

Since your requirements are probably different from the examples shown here (e.g., you might want to start different programs, you might want to add code to decide which programs start on which nodes, etc.), the QSTARTX program is completely user-defined. In fact, QSTARTX is optional (if you don’t have a program named QSTARTX, Comet proceeds directly to CMONITOR and QMONITOR).



Copyright © 1995 - 2007 Signature Systems, Inc.

Personal tools