MQ

 View Only
Expand all | Collapse all

MQ manager autostart after AWS reboot

  • 1.  MQ manager autostart after AWS reboot

    Posted Thu January 11, 2024 06:20 PM

    Hi!

    I'm trying to make the MQ Manager autostart after the AWS Instance restart or reboot. 

    Basically trying to run a bash script when the server start but nothing happens...

    #!/bin/bash
    # Start queue managers
    qmgrs=( $(dspmq | grep -v "Running" | cut -d "(" -f2 | cut -d ")" -f1) )
    for i in "${qmgrs[@]}"
    do
    :
    strmqm "$i"
    done



    Thank you!



    ------------------------------
    Juan Reforme
    ------------------------------


  • 2.  RE: MQ manager autostart after AWS reboot

    IBM Champion
    Posted Fri January 12, 2024 09:34 AM

    Try this

    #!/bin/bash
    #
    
    dspmq | grep -v Running | cut -d "(" -f 2 | cut -d ")" -f 1 > test.dat
    while read line
    do
    #       echo "line = $line"
            strmqm $line
    done < test.dat
    


    ------------------------------
    Francois Brandelik
    ------------------------------



  • 3.  RE: MQ manager autostart after AWS reboot

    IBM Champion
    Posted Fri January 12, 2024 10:49 AM

    If using HA qmgrs; it would auto start on the next available host.

    Is the environment you setting it up, just a standalone queue manager?



    ------------------------------
    om prakash
    ------------------------------



  • 4.  RE: MQ manager autostart after AWS reboot

    Posted Fri January 12, 2024 11:21 AM
    Edited by Matheus Francisco Tue January 16, 2024 04:43 AM

    You can run as a systemd service, example:

    [Unit]
    Description=IBM MQ queue manager {QueueManagerName}
    Wants=network-online.target
    After=network.target
    
    
    [Service]
    ExecStart=/opt/mqm/bin/strmqm -x {QueueManagerName}
    ExecStop=/opt/mqm/bin/endmqm -w -s {QueueManagerName}
    SuccessExitStatus=0 5 30 77
    Type=forking
    User=mqm
    Group=mqm
    KillMode=none
    LimitNOFILE=10240
    LimitNPROC=4096
    
    
    [Install]
    WantedBy=multi-user.target

    ------------------------------
    Matheus Francisco
    ------------------------------



  • 5.  RE: MQ manager autostart after AWS reboot

    Posted Fri January 12, 2024 06:18 PM

    Thank you all, This works very well as expected!



    ------------------------------
    Juan Reforme
    ------------------------------



  • 6.  RE: MQ manager autostart after AWS reboot

    Posted Tue January 16, 2024 01:00 AM

    Need code that works?

    #!/bin/bash
    for qm in $(dspmq | grep -v Running | cut -d'(' -f2 | cut -d')' -f1) ; do
    strmqm $qm
    done

    Preferred solution for Linux is to use systemd.



    ------------------------------
    Glenn Baddeley
    Senior Middleware Software Engineer
    Coles Supermarkets Australia Pty Ltd
    ------------------------------



  • 7.  RE: MQ manager autostart after AWS reboot

    IBM Champion
    Posted Tue January 16, 2024 08:49 PM

    regarding using systemd to start/stop a MQ Queue Manager, is it better to have systemd call the strmqm / endmqm commands directly, or better to have systemd call a ksh script that then calls startmqm/endmqm and whatever else the script may do?



    ------------------------------
    Peter Potkay
    ------------------------------



  • 8.  RE: MQ manager autostart after AWS reboot

    Posted Wed January 17, 2024 02:17 AM

    I would always go via a script.

    That way you can add things like your own logging, perhaps you need to do setmqenv or run from non-default directories, maybe do extra work during shutdown like forcibly killing apps that won't go away on their own ...



    ------------------------------
    Mark Taylor
    Winchester
    ------------------------------



  • 9.  RE: MQ manager autostart after AWS reboot

    Posted Thu January 18, 2024 02:37 PM
    1. Don't even try to setup MQ systemd as a "user" service unless you really want it to start when the user logs on, and stop when the user exits. .  Its an effort in futility.  
    2. When starting MQ from systemd in addition to using a script it is important to setup the ulimits that typically come with a login, but are not provided by systemd since systemd doesnt 'logon':

    e.g.  mq.service 

     

    [Unit]
    Description=systemd file to start MQ
    Wants=centrifydc.service
    After=centrifydc.service
    
    [Service]
    # Note in this example the actual location of the script is being purposefully obfuscated 
    # to prevent discovery of infrastructure.
    ExecStart=/usr/bin/bash -c '<targetdir>/mqnace startmq'
    ExecStop=/usr/bin/bash -c '<targetdir>/mqnace stopmq'
    User=mqm
    Type=forking
    KillMode=none
    LimitAS=infinity
    LimitCORE=infinity
    LimitDATA=infinity
    LimitFSIZE=infinity
    LimitMEMLOCK=65535
    LimitMSGQUEUE=819200
    LimitNOFILE=1048576
    LimitNPROC=1048576
    LimitRSS=infinity
    LimitSIGPENDING=192441
    LimitSTACK=8192000
    TimeoutStartSec=3600
    TimeoutStopSec=240
    [Install]
    WantedBy=multi-user.target

    3. On our hosts we use a single script that derives the queue manager and broker info from the hostname and handles both the start and stop of mq AND/OR ACE as appropriate.

    4. Endmqm may not in some cases be sufficient: there are some processes that dont stop nicely,  so the script needs to do something like 

    # Brutally Killing any remaining mq processes"          
                for PROCESS in "${MQ_PROCESSES}"
                do # Output of kill redirected to /dev/null in case no processes
                    ps -ef | grep "$PROCESS" | grep -v grep | \
                    awk '{print $2}'| xargs kill -9
                done



    ------------------------------
    Anthony Julian
    ------------------------------



  • 10.  RE: MQ manager autostart after AWS reboot

    IBM Champion
    Posted Fri January 19, 2024 10:54 AM

    The script that is called by systemd to start the queue manager, couldn't it do something like this to accomplish the "logon" to pick up mqm's ulimits, env variables, etc

    runuser -l  mqm -c "/opt/mqm/bin/strmqm $QMGR" 



    ------------------------------
    Peter Potkay
    ------------------------------



  • 11.  RE: MQ manager autostart after AWS reboot

    Posted Fri January 19, 2024 03:11 PM

    This probably would work.  In our case most of our queue managers run on one - and only one of a pair:  therefore we needed logic to figure out which host was designated active in the pair.  

    For configuration management reasons, we wanted to have a single script that would execute on any of our 100+ mq hosts handling both start and stop. In addition, as I remarked under some circumstances endmqm does not stop all the mqm processes on the host so scripting the stop was a requirement.

    We chose also to have the same script handle the start/stop ace which simplifies the configuration management even more.

    We experimented with systemd templates , but the management  was more convoluted and prone to error.



    ------------------------------
    Anthony Julian
    ------------------------------



  • 12.  RE: MQ manager autostart after AWS reboot

    IBM Champion
    Posted Mon January 22, 2024 03:16 PM

    How do we prove to ourselves that the queue manager is in fact running with the system variable we think its running with?  I noticed at the bottom of an FDC file the queue manager shows a lot of that. Is there a way to cause the queue manager to eject a harmless info only FDC that we can then look at?



    ------------------------------
    Peter Potkay
    ------------------------------



  • 13.  RE: MQ manager autostart after AWS reboot

    IBM Champion
    Posted Thu February 08, 2024 08:07 PM

    Here is how to safely generate an FDC to then go look at the environment dump at the end of the FDC.

    How to find out if an MQ queue manager was started with a specific environment variable (ibm.com)



    ------------------------------
    Peter Potkay
    ------------------------------