Solved

Start QSH command from CL

Posted on 2014-09-10
19
1,243 Views
Last Modified: 2014-09-19
I am attempting to start Redis from a CL program.  Typically, this is the process I use to start Redis:

CALL QP2TERM
CD /QOPENSYS
/QOpensys/opt/freeware/sbin/redis-server  --logfile /redislog/redis-server.log --maxmemory 1GB

I want to do this from a CL instead of manually through command line.  Does anyone know how I can accomplish this?

Any help is much appreciated.
0
Comment
Question by:Matthew Roessner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 9
19 Comments
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 40315341
Use qp2shell:

http://forums.iprodeveloper.com/forums/aft/49452

Create a little shell script that does this:

CD /QOPENSYS
/QOpensys/opt/freeware/sbin/redis-server  --logfile /redislog/redis-server.log --maxmemory 1GB

Then run  that script by calling qp2shell.
- Gary
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40315384
I don't have any experience with creating shell scripts.

I just created something in the /redislog directory. I just did a

EDTF '/redislog/startredis'

Then I pasted in the two commands:

CD /QOPENSYS
/QOpensys/opt/freeware/sbin/redis-server  --logfile /redislog/redis-server.log --maxmemory 1GB

I saved that...and then created a CL with the following:

 CALL       PGM(QP2SHELL) PARM('/redislog/startredis')

This didn't work...  Got the following:

Error loading i5/OS PASE program /redislog/startredis
0
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 40315537
New files aren't created with execute authority.

Go into PASE,

chmod 0755 /redislog/startredis

To make the script executable, and try it again.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40316680
I did the following:

CALL QP2TERM

$ chmod 0755 /redislog/startredis

After doing this, I re-ran it and I again got the following:

i5/OS PASE program or shell script not executable. Path is /redislog/startredis.                                              
Error loading i5/OS PASE program /redislog/startredis.  See previous messages.
0
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 40317214
To call from qp2shell, you need this as the top line of your script:

#!/usr/bin/sh

Also make sure the script file is in ASCII (CCSID 819 on my US-localized machine), and uses LF as the new line terminator.  This is one way to do it from a QP2TERM:

echo \#!/usr/bin/sh > /redislog/startredis
echo CD /QOPENSYS >> /redislog/startredis
echo /QOpensys/opt/freeware/sbin/redis-server  --logfile /redislog/redis-server.log --maxmemory 1GB >> /redislog/startredis

chmod 0755 /redislog/startredis

Open in new window

0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40317649
I think we are almost there. I am able to start Redis now from my program...but the program never "completes".  Is there any way to "exit" the Qshell?

If I simply call my program:  CALL LIBRARY/REDISSTR - I get an X on my screen and control is never returned.  I see the following in my QBATCH sbs:

STARTREDIS   QSYSOPR     BCH      .0  PGM-sh           THDW
STARTREDIS   QSYSOPR     BCI      .0  PGM-redis-serv   SELW

Basically it looks like the top job (the PGM-sh) has control.  Essentially the same thing happens if I do a SBMJOB.  

Any idea how to get that part to end - but to keep the bottom job running?

I really appreciate all the help!

Matt
0
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 40317791
Try putting the "source" command or "exec" command in front of the redis-server command:

source /QOpensys/opt/freeware/sbin/redis-server  --logfile /redislog/redis-server.log --maxmemory 1GB

or

exec /QOpensys/opt/freeware/sbin/redis-server  --logfile /redislog/redis-server.log --maxmemory 1GB

"source" says to run the program/script in the current shell instead of spawning a new one.  If the redis-server program ends eventually, the next line of your startredis script would then run, if there was one.

"exec" says to run the program.script IN PLACE OF the current shell.  So control gets transferred to redis-server.  When it ends the shell will end, and if there were more lines in the startredis script they would never be executed.
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40317831
I attempted to use both EXEC and SOURCE.  When I used either of these and ran my program:

CALL <LIBRARY>/REDISSTR


Nothing happens...  The Redis job does not start (but control is returned...)  Essentially it looks like the command runs but it doesn't do anything
0
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 40317887
Just to clarify, this is not qshell.  

It is PASE, which defaults to the bash shell.  QP2TERM and QP2SHELL start the PASE environment.  QSH command starts the qshell environment.
0
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 40317900
OK, so I assume you have a CL called REDISSTR.

In it you have the CALL QP2SHELL command.  When you use the script with a direct invocation of redis-server, the job with your CL running in it hangs waiting for the CALL to complete (which it won't because redis-server is a server that is supposed to start and stay running).

And when you try to use source or exec, the redis-server doesn't appear to start properly.

Why not just submit the CALL QP2SHELL command to batch instead of calling it from a CL?  Does that do what you want?
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40333003
Sorry I have been out of the office this week.

When I just run the CALL QP2SHELL command:

CALL PGM(QP2SHELL) PARM('/redislog/startredis')

I get the following message from within the QSH screen:

/redislog/startredis[3]: /QOpensys/opt/freeware/sbin/redis-server --logfile /
redislog/redis-server.log --maxmemory 1GB:  not found.                      
Press ENTER to end terminal session.                                        

Then I have to press enter to return to the command line. The Redis server does not start...

I appreciate all your help thus far...
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40333030
I apologize for the previous post. I still had the EXEC command inside of my startredis shell script.

I can not call the:

CALL       PGM(QP2SHELL) PARM('/redislog/startredis')

from a command line, but it essentially freezes the screen (with a X in the window) and stays active. It shows the following jobs running:

REDIS_TEST   QSYSOPR     BCH      .0  PGM-sh           THDW
REDIS_TEST   QSYSOPR     BCI      .0  PGM-redis-serv   SELW

The top job should not be running, but the bottom job should.  I attempted to start this via a SBMJOB command, but I get the same thing (minus the hung session).

Any ideas?
0
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 40333118
That looks right to me.  redis-server is a server-style job / a daemon / a never-ending program, and you're having trouble getting it to run in the initial shell - so let it spawn its own thread and run.  Normally you'd submit this to batch or set it up as an auto-start job.  

Is the only problem that you just don't like the look of the BCH job hanging there?  If so, just start it form batch.  you generally start a server job like this from a job scheduler or from an autostart job anyway.  The "hanging" initial shell is functioning perfectly - it is just waiting for redis-server to end, and it will terminate when it does.
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40333181
When you say "Submit to batch" - do you mean from a iSeries command line?

When I do this - it freezes my screen that I submit from.

From the command line, I call the following:

CALL       PGM(QP2SHELL) PARM('/redislog/startredis')

This freezes my screen...
0
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 40333275
You use the SBMJOB command to submit a batch job.  Specific parameters to run in your environment are going to vary.  Do you have a sysadmin who can help you?
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40333326
I did try submitting the job via the SBMJOB command:

SBMJOB CMD(CALL PGM(QP2SHELL) PARM('/redislog/startredistest')) JOB(REDIS_TEST) JOBQ(*LIBL/QREDIS) USER(QSYSOPR)  

When I do it this way - 2 jobs start - like I said above:

REDIS_TEST   QSYSOPR     BCH      .0  PGM-sh           THDW
REDIS_TEST   QSYSOPR     BCI      .0  PGM-redis-serv   SELW

Control is returned to the screen this way - I would just rather not have the BCH job running...
0
 
LVL 35

Accepted Solution

by:
Gary Patterson earned 500 total points
ID: 40333437
Yes.  Based on what you are doing, that is how it should look.  I bash when a script calls another script like this a new shell is spawned.  The way to stop that behavior is by using source or exec and you said that didn't work when you use qp2shell.  That isn't a surprise.

I understand that you don't like the way it looks, but this is how this is supposed to work based on what you are doing.  

- Gary
0
 
LVL 1

Author Comment

by:Matthew Roessner
ID: 40333439
Thanks for all your help
0
 
LVL 1

Author Closing Comment

by:Matthew Roessner
ID: 40333442
Very helpful
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Determining the an SCCM package name from the Package ID
The goal of this blog is: - To define the incident management process - To go over the key elements of an incident management system - To look into incident alert management tools that integrate with ConnectWise.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question