In this post, I would like to share how to implement automatic Start and Stop for CONTROL-M/Server, CONTROL-M/Agent and CONTROL-M/EM running on Oracle linux 7 individual servers, by implementing some updates in the existing BMC procedure and script.
The CONTROL-M should be running version 9 and we are using the internal PostgreSQL database.
The user created for CONTROL-M/Server and CONTROL-M/Agent environment is ctmuser, the user created for CONTROL-M/EM environment is emuser.

BMC CONTROL-M Workload Automation documentation

CONTROL-M/Server

With ctmuser, update existing rc.ctmuser file provided with the BMC distribution by adding the start_ctm part. /home/ctmuser is the home directory of the installation. This command was missing from the existing script, and will guarantee a proper startup of the CONTROL-M Server. The rc.ctmuser script content will then be as following.

    ctmsrv% cat /home/ctmuser/ctm_server/data/rc.ctmuser

    # start database at boot
    su - ctmuser -c dbversion
    if [ $? -eq 0 ] ; then
      echo "SQL Server is already running "
    else
      if [ -f /home/ctmuser/ctm_server/scripts/startdb ]; then
      echo "Starting SQL server for CONTROL-M"
      su - ctmuser -c startdb
      echo "Sleeping for 20"
      sleep 20
      fi
    fi

    # start CONTROL-M Server at boot
    if [ -f /home/ctmuser/ctm_server/scripts/start_ctm ]; then
    echo "Starting CONTROL-M Server"
    su - ctmuser -c /home/ctmuser/ctm_server/scripts/start_ctm &
    sleep 5
    fi

    # start CONTROL-M Configuration Agent at boot
    if [ -f /home/ctmuser/ctm_server/scripts/start_ca ]; then
    echo "Starting CONTROL-M Server Configuration Agent"
    su - ctmuser -c /home/ctmuser/ctm_server/scripts/start_ca &
    sleep 5
    fi

    exit 0

    ctmsrv%

 

The existing BMC procedure does not include any script to be run when the service or the physical server is shutdown. Processes will then simply be killed, which will not guarantee a proper stop of the application and most important the internal PostgreSQL database.
With ctmuser, create a new rc file for stop purpose. Let’s name the file rc.stop.ctmuser and have it located in same /home/ctmuser/ctm_server/data directory. The file content will be the following.

    ctmsrv% cat /home/ctmuser/ctm_server/data/rc.stop.ctmuser
    # stop CONTROL-M Configuration Agent at poweroff/reboot
    if [ -f /home/ctmuser/ctm_server/scripts/shut_ca ]; then
      echo "Stopping CONTROL-M Server Configuration Agent"
      su - ctmuser -c /home/ctmuser/ctm_server/scripts/shut_ca &
      sleep 5
    fi

    # stop CONTROL-M Server at poweroff/reboot
    if [ -f /home/ctmuser/ctm_server/scripts/shut_ctm ]; then
      echo "Stopping CONTROL-M Server"
      su - ctmuser -c /home/ctmuser/ctm_server/scripts/shut_ctm &
      sleep 5
    fi

    # stop database at poweroff/reboot
    if [ -f /home/ctmuser/ctm_server/scripts/shutdb ]; then
      echo "Stopping SQL server for CONTROL-M"
      su - ctmuser -c shutdb
      echo "Sleeping for 20"
      sleep 20
    fi


    exit 0

 

With root privileges, create the service file as below. We will be adding the ExecStop part additionnaly to the existing BMC procedure.

    [root@ctmsrv system]# cat /etc/systemd/system/ctmserver.service
    [Unit]
    Description=CONTROL-M Server
    After=systemd-user-sessions.service multi-user.target network.target
    [Service]
    ExecStart=/bin/sh -c /home/ctmuser/ctm_server/data/rc.ctmuser
    ExecStop=/bin/sh -c /home/ctmuser/ctm_server/data/rc.stop.ctmuser
    Type=forking
    RemainAfterExit=yes
    [Install]
    WantedBy=multi-user.target

 

Give appropriate file permissions and enable the service. A system reboot will be necessary.

    [root@ctmsrv system]# chmod 644 ctmserver.service
    [root@ctmsrv system]# systemctl daemon-reload
    [root@ctmsrv system]# systemctl enable ctmserver.service
    Created symlink from /etc/systemd/system/multi-user.target.wants/ctmserver.service
      to /etc/systemd/system/ctmserver.service.
    [root@ctmsrv system]# systemctl reboot

 

A well-functioning test can be performed by running service ctmserver stop/start with root privileges and monitoring results of :

  • watch ‘ps -ef | grep ctm’
  • ctm_menu
  • service ctmserver status

 CONTROL-M/Agent

For the Agent we will apply the existing BMC procedure.
With root privileges, create the service file as described  below.

    [root@ctmagtli1 system]# cat /etc/systemd/system/ctmag.service
    [Unit]
    Description=CONTROL-M Agent
    [Service]
    Type=forking
    RemainAfterExit=yes
    ExecStart=/home/ctmuser/ctmagent/ctm/scripts/rc.agent_user start
    ExecStop=/home/ctmuser/ctmagent/ctm/scripts/rc.agent_user stop
    [Install]
    WantedBy=multi-user.target

 

Give appropriate file permissions and enable the service. A system reboot will be necessary.

    [root@ctmagtli1 system]# chmod 644 ctmag.service
    [root@ctmagtli1 system]# systemctl daemon-reload
    [root@ctmagtli1 system]# systemctl enable ctmag.service
    Created symlink from /etc/systemd/system/multi-user.target.wants/ctmag.service
      to /etc/systemd/system/ctmag.service.
    [root@ctmagtli1 system]# systemctl reboot

 

A well-functioning test can be performed by running service ctmag stop/start with root privileges and monitoring results of :

  • watch ‘ps -ef | grep ctm’
  • /home/ctmuser/ctmagent/ctm/scripts/ag_diag_comm
  • service ctmag status

CONTROL-M/EM

For EM we will apply the existing BMC procedure.
With root privileges, create the service file as described  below.

    [root@emserver system]# cat /etc/systemd/system/EM.service
    [Unit]
    Description=CONTROL-M/EM
    After=systemd-user-sessions.service multi-user.target network.target
    [Service]
    User=emuser
    ExecStart=/bin/sh -c /home/emuser/bin/start_server;/home/emuser/bin/start_ns_daemon;/home/emuser/bin/start_cms;/home/emuser/bin/start_config_agent
    Type=forking
    RemainAfterExit=yes
    ExecStop=/bin/sh -c /home/emuser/bin/stop_config_agent;/home/emuser/bin/stop_cms;/home/emuser/bin/stop_ns_daemon;/home/emuser/bin/home/em50/bin/stop_server
    [Install]
    WantedBy=multi-user.target

 

Give appropriate file permissions and enable the service. A system reboot will be necessary.

    [root@emserver system]# chmod 644 EM.service
    [root@emserver system]# systemctl daemon-reload
    [root@emserver system]# systemctl enable EM.service
    Created symlink from /etc/systemd/system/multi-user.target.wants/EM.service
      to /etc/systemd/system/EM.service.
    [root@emserver system]# systemctl reboot

 

A well-functioning test can be performed by running service EM stop/start with root privileges and monitoring results of :

  • watch ‘ps -ef | grep em’
  • root_menu
  • service EM status