Start QSH command from CL

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.
LVL 1
Matthew RoessnerSenior Systems ProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gary PattersonVP Technology / Senior Consultant Commented:
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
Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
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
Gary PattersonVP Technology / Senior Consultant Commented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
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
Gary PattersonVP Technology / Senior Consultant Commented:
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
Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
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
Gary PattersonVP Technology / Senior Consultant Commented:
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
Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
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
Gary PattersonVP Technology / Senior Consultant Commented:
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
Gary PattersonVP Technology / Senior Consultant Commented:
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
Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
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
Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
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
Gary PattersonVP Technology / Senior Consultant Commented:
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
Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
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
Gary PattersonVP Technology / Senior Consultant Commented:
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
Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
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
Gary PattersonVP Technology / Senior Consultant Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
Thanks for all your help
0
Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
Very helpful
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
IBM System i

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.