Start/Stop HTTP Server for IBM i for Everyone

Simplified Start/End HTTP Server CL Command

Most shops either do not have an HTTP server running on their #IBMi server or if they do, they only have the *ADMIN instance running. For a growing number of #IBMi shops, however, the HTTP server is not only started, but is being used to support end-user applications with a fresh browser-based user interface.

History Lesson

Back when STRTCPSVR *HTTP first came about, a number of users (myself included) ran into a little issue with it. If you wanted to END the HTTP Web server you typed in ENDTCPSVR *HTTP HTTPSVR(MYWEB) or simply left off the HTTPSVR parameter which defaults to *ALL.

The bad news is that the first parameter (where I typed in *HTTP) was not and still to this day, is not a required parameter. And the really bad news is that if you were to type in ENDTCPSVR <Enter> you would have a learning experience or worse.

One Sunday afternoon as I was working on my old MidrangeNews.com website, I needed to restart the web server, so I quickly typed in ENDTCPSVR and pressed Enter instead of F4, because, well, required parameter forced an auto-prompt situation for a few years by that time so I never in a million years though ENDTCPSVR SERVER(*ALL) was a default! I'm mean, how did that get through the system user experience checks? So I watched as the messages flashed before my eyes...

  • Ending *DDM server
  • Ending *DHCP server
  • Ending *DNS server
  • Ending *FTP server
  • Ending *HTTP server
  • ... and it continued until...
  • Ending *TELNET server
  • .............

Once TELNET was stopped, and since HTTP was stopped, my only option was to go into the Office and force an IPL. While an HMC would've helped with that (we've never owned an HMC) the fact that it happened was un-f'ng believable.

A year or so later, IBM introduces a change that did not fix this issue, but made you feel silly and scared. Nowadays a dialog box is displayed that says (and I'm paraphrasing it here) "Hey buddy, are you sure you want to shut down all the TCP/IP servers? That would be unfortunate and could result in early termination of your employment agreement."

My Solution: The STR/END HTTP Server CL Command

To solve this problem today, I no longer use the STRTCPSVR or ENDTCPSVR commands. I ONLY ever have to stop/start HTTP servers, so why use a machine gun (ENDTCPSVR) simply to swat a fly?

In addition, why would anyone have authority to ENDTCPSVR other than for the HTTP servers? Sure you need to sometimes restart the DDM or FTP servers, but that's rare and exception-based. But developers who are building web applications often need to restart the HTTP Server Instance for their web instance.

I feel like ENDTCPSVR *HTTP HTTPSVR(blah) followed by STRTCPSVR *HTTP HTTPSVR(blah) is the IBM i version of Ctrl-Alt-Del.

So I created two new commands:

  1. Start HTTP Server (STRHTTPSVR)
  2. End HTTP Server (ENDHTTPSVR)

These two commands limit the TCP/IP Servers that may be started or ended to only HTTP servers. This means you can give them to developers building your web apps and not worry about them terminating the Telnet or other important TCP/IP servers. Here's how it is used:

ENDHTTPSVR MYSTUFF
STRHTTPSVR MYSTUFF        

Not rocket science but a useful enough function to warrant being used on every system out there, IMHO.

If you have more than one HTTP server you're working with (as I do) you often want to start up or end multiples. So I've build the command to allow multiple server instance names, like so:

ENDHTTPSVR HTTPSVR(MYSTUFF OTHERSTUFF)        

Up to 300 instance names my be specified for the HTTPSVR parameter, which is the CL maximum.

The source code for this CL command is pretty simple so I'll show that first.

 STRHTTPSVR: CMD        PROMPT('Start TCP/IP *HTTP Servers')
             PARM       KWD(HTTPSVR) TYPE(*NAME) LEN(10) +
                          SPCVAL((*ADMIN)) SNGVAL((*ALL)) MIN(1) +
                          MAX(300) EXPR(*YES) PROMPT('HTTP Server name')        

As you can see, it has only one parameter, HTTPSVR which matches the name for that same parameter on the STRTCPSVR command. However no options are supported by the STRHTTPSVR command but you could add those if you need them. It does support the *ADMIN and *ALL special values if needed. Now lets look at the CL source code that drives this command:

 STRHTTPSVR: PGM        PARM(&SERVERS)
             DCL        VAR(&SERVERS) TYPE(*CHAR) LEN(3002)
             DCL        VAR(&COUNT) TYPE(*INT) STG(*DEFINED) LEN(2) +
                          DEFVAR(&SERVERS)
             DCL        VAR(&SVRLIST) TYPE(*CHAR) STG(*DEFINED) +
                          LEN(3000) DEFVAR(&SERVERS 3)
             DCL        VAR(&HTTPSVR) TYPE(*CHAR) LEN(10)
             DCL        VAR(&POS) TYPE(*INT) LEN(4)
             DCL        VAR(&I) TYPE(*INT) LEN(4)

             DOFOR      VAR(&I) FROM(1) TO(&COUNT)
                CHGVAR     VAR(&POS) VALUE(1 + ((&I - 1) * 10))
                CHGVAR     VAR(&HTTPSVR) VALUE(%SST(&SVRLIST &POS 10))
                IF (&HTTPSVR *NE ' ') THEN(DO)
                   SNDPGMMSG  MSGID(CPF9897) MSGF(QCPFMSG) +
                     MSGDTA('Starting TCP/IP *HTTP Server' *BCAT &HTTPSVR)
                   STRTCPSVR  SERVER(*HTTP) HTTPSVR(&HTTPSVR)
                   MONMSG     MSGID(CPF0000 TCP0000)
                ENDDO
             ENDDO

 ENDPGM:     ENDPGM        

The CL program loops through a STRTCPSVR *HTTP for each server specified on the HTTPSVR parameter of the STRHTTPSVR command. It traps any messages, but you'll be able to review them in the joblog or on Command Entry. I've been using it and ENDHTTPSVR for a while now, and have trained myself to type in ENDHTTPSVR instead of the original rattle snake STRTCPSVR command.

The ENDHTTPSVR command is just as simple and structurally similar.

 ENDHTTPSVR: CMD        PROMPT('End TCP/IP *HTTP Servers')
             PARM       KWD(HTTPSVR) TYPE(*NAME) LEN(10) +
                          SPCVAL((*ADMIN)) SNGVAL((*ALL)) MIN(1) +
                          MAX(300) EXPR(*YES) PROMPT('HTTP Server to end')        

And its CL code:

 ENDHTTPSVR: PGM        PARM(&SERVERS)
             DCL        VAR(&SERVERS) TYPE(*CHAR) LEN(3002)
             DCL        VAR(&COUNT) TYPE(*INT) STG(*DEFINED) LEN(2) +
                          DEFVAR(&SERVERS)
             DCL        VAR(&SVRLIST) TYPE(*CHAR) STG(*DEFINED) +
                          LEN(3000) DEFVAR(&SERVERS 3)
             DCL        VAR(&HTTPSVR) TYPE(*CHAR) LEN(10)
             DCL        VAR(&POS) TYPE(*INT) LEN(4)
             DCL        VAR(&I) TYPE(*INT) LEN(4)

             DOFOR      VAR(&I) FROM(1) TO(&COUNT)
                CHGVAR     VAR(&POS) VALUE(1 + ((&I - 1) * 10))
                CHGVAR     VAR(&HTTPSVR) VALUE(%SST(&SVRLIST &POS 10))
                IF (&HTTPSVR *NE ' ') THEN(DO)
                   SNDPGMMSG  MSGID(CPF9897) MSGF(QCPFMSG) +
                     MSGDTA('Ending TCP/IP *HTTP Server' *BCAT &HTTPSVR)
                   ENDTCPSVR  SERVER(*HTTP) HTTPSVR(&HTTPSVR)
                   MONMSG     MSGID(CPF0000 TCP0000)
                ENDDO
             ENDDO

 ENDPGM:     ENDPGM        

If you're unfamiliar with compiling user-written CL commands, the CRTCMD command (yes, "Create command command") is what you use. You have to identify the program to run when the command is entered. That program is called the Command Processing Program or simply, the CPP. It is specified on the PGM parameter of CRTCMD as follows:

CRTCMD CMD(COZTOOLS/STRHTTPSVR) PGM(COZTOOLS/STRHTTPSVR) SRCFILE(COZTOOLS/QCLSRC)
CRTCLPGM PGM(COZTOOLS/STRHTTPSVR) SRCFILE(COZTOOLS/QCLSRC)
 
/* Then the ENDHTTPSVR command */
CRTCMD CMD(COZTOOLS/ENDHTTPSVR) PGM(COZTOOLS/ENDHTTPSVR) SRCFILE(COZTOOLS/QCLSRC)
CRTCLPGM PGM(COZTOOLS/ENDHTTPSVR) SRCFILE(COZTOOLS/QCLSRC) 
        

Now you can use STRHTTPSVR and ENDHTTPSVR on your system and allow users (i.e., programmers) to start and end their own instances without worrying that they might accidentally shut down the system.

That's all there is to it.

I was always amazed by the dramatic (black) hole inherent to the use of ENDTCPSVR. This is a complete, efficient an elegant solution!

Like
Reply

"Hey buddy, are you sure you want to shut down all the TCP/IP servers? That would be unfortunate and could result in early termination of your employment agreement." 😆😆😆

PWRDWNSYS when accidentally invoked on a hot production system is a terrible thing to watch unfold, you are over the event horizon and there’s no turning back. Thank God I’ve never done that myself but I’ve received the help desk call a few times when I worked for E & J Gallo. I would tell them to get everyone off the system and plan on 90 minutes of downtime. If they still had a command prompt we would have them reissue the command as *IMMED after verifying the application subsystems were down. Many years ago under V4 we had a network consultant on-site who loudly announced “I’m ending TCP/ip”. On a hot system in the middle of a business day. That went over real well 🙄.

To view or add a comment, sign in

More articles by Bob Cozzi

  • Convert Fixed Format RPG IV to Free Format UPDATE

    Just a quick update. We are not at version 0.

    6 Comments
  • Convert to RPG IV Free Format in VS CODE

    During Spring break (in the U.S.

    16 Comments
  • Using my READSPLF SQL Function

    A SQL Table Function to Directly Read IBM i Spooled Files Managing spooled files on IBM i has always been a critical…

    8 Comments
  • Example SQL iQuery Script for IBM i

    Since releasing SQL iQuery for the IBM i operating system, my customers have primarily been using a very cool feature…

    3 Comments
  • Reading Source File Members Using SQL

    With the introduction of my SQL Tools product several years ago, I created a number of "READ" SQL functions that…

    3 Comments
  • IBM i SQL Function Adoption Rate

    IBM i Developers have long relied on various interfaces and tools to navigate system functions, but many remain unaware…

    3 Comments
  • SQL iQuery for Web Config Directives

    Last time I showed how to use the no-charge SQL iQuery for Web product to create a simple File Inquiry web app for the…

    1 Comment
  • HTML/Browser Apps for IBM i

    There have been myriad methods for creating HTML browser enabled applications that use IBM i database files. For the…

    12 Comments
  • SQL iQuery is Free (tell your friends)

    Challenges of Pricing Software in the IBM i Ecosystem In the dynamic arena of technology services and software support…

    9 Comments
  • IBM i SQL UDTF: SYSINFO

    I had a post about a simple SQL Function I created that gives me everything I need to know about the physical Power…

Others also viewed

Explore content categories