More than likely you have run into a situation where you wanted a program or command to run automatically when, for example, the system IPL'd. The obvious solution in this instance is to put the necessary code into your start-up program (i.e., the program specified for the QSTRUPPGM system value). But what do you do when, for example, you want a program to run automatically only when a specific subsystem is started? Some reasons you may want to do this:
- To set up a special environment when the QSNADS or QSERVER subsystem starts.
- To start the print writers when the QSPL subsystem starts.
The solution: Attach an autostart job entry to the subsystem
An autostart job entry is a job that runs automatically when a subsystem is started. In fact, the system start-up program is called from the autostart job entry QSTRUPJD attached to the QCTL and QBASE subsystems. Note: This is the default configuration; your configuration may vary.
- Information on the autostart program
- Using the startup program
- Start and stop jobs without creating security holes
An autostart job entry consists of a job name and a job description. The job description is the key. Every job description has an attribute called the request data. When you create a job description using the CRTJOBD command, one of the parameters is Request data or command (RQSDTA). The system runs the command specified for this parameter whenever a job is started using the job description. When the job description is "attached" to a subsystem description in one of its autostart job entries, the job description's request data command will then become the autostart program (or command).
Three steps to set up an autostart program
Follow these steps to set up and attached an autostart program to a subsystem so that each time the subsystem is started, the autostart program is executed:
- Create the autostart program. This program is responsible for doing whatever it is you want to do. For example, say we create program AJEPGM in library QUSRSYS. Note: If you merely want to execute a single system command, such as STRPRTWTR DEV(PRT02), you can skip this step since you can just specify such a command as the request data.
Create a job description. On the request data parameter (RQSDTA), specify a call to the program created in step 1 (or specify the system command if you did not create an autostart program). For example, we can create a job description AJEJOBD in library QUSRSYS with the following command:CRTJOBD JOBD(QUSRSYS/AJEJOBD) USER(QPGMR)You must specify a user profile name on the USER parameter. The default *RQD is not valid for job descriptions used for autostart jobs. The user profile specified must also have the necessary authority, as the autostart job will run under that profile.
Add an autostart job entry to the subsystem. Use the ADDAJE command to "link" the job description to the subsystem description. The following command links the job description created in step 2 to the subsystem description QBATCH:ADDAJE SBSD(QBATCH) JOB(TESTAJE)
Four important things to remember when using autostart jobs
- Autostart jobs run in batch, so only batch commands are valid.
- Autostart jobs run in the subsystem for which they are specified unless specifically submitted to another subsystem.
- Autostart job entries can be added and removed while the subsystem is active.
- Use the RMVAJE command to remove an Autostart job entry from a subsystem description.
About the author: Ron Turull is editor of Inside Version 5. He has more than 20 years' experience programming for and managing AS/400-iSeries systems.