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
    ------------------------------