0

I have an upstart script as

   # Ubuntu upstart file at /etc/init/wso2am.conf
#!upstart
description "wso2am" 

pre-start script
    mkdir -p /var/log/wso2am/
end script

respawn
respawn limit 15 5

start on runlevel [2345]
stop on runlevel [06]

script
    # Not sure why $HOME is needed, but we found that it is:
    export JAVA_HOME="/usr/lib/jvm/jdk1.8.0_111"

    #exec /usr/local/bin/node $JAVA_HOME/node/notify.js 13002 >> /var/log/node.log 2>&1
end script

And my service file also created as

# this is /usr/lib/systemd/system/wso2am.service
# (or /lib/systemd/system/wso2am.service dependent on 
#  your linux distribution flavor )
[Unit]
Description=wso2am server daemon
Documentation=https://docs.wso2.com/
After==network.target wso2am.service

[Service]
# see man systemd.service 
User=tel
Group=tel
TimeoutStartSec=0
Type=simple
KillMode=process
ExecStart= /bin/bash -lc '/home/tel/Documents/vz/wso2am-2.1.0/wso2am-2.1.0/bin/wso2server.sh --start'
RemainAfterExit=true
ExecStop = /bin/bash -lc '/home/tel/Documents/vz/wso2am-2.1.0/wso2am-2.1.0/bin/wso2server.sh --stop'
StandardOutput=journal
Restart = always
RestartSec=2

[Install]
WantedBy=default.target 

I try to kill process (wso2am)

ps -ef | grep wso2am
Kill -9 process_id

Process status

But i can't able to find process automatically respawn/restart. How to check auto-respawn mechanism in ubuntu?

Community
  • 1
  • 1
VIVEK-MDU
  • 2,483
  • 3
  • 36
  • 63

1 Answers1

1

You can achieve this through systemd with your wso2am.service file modified as follows.

[Unit]
Description=wso2am server daemon
Documentation=https://docs.wso2.com/
After=network.target

[Service]
ExecStart=/bin/sh -c '/home/tel/Documents/vz/wso2am-2.1.0/wso2am-2.1.0/bin/wso2server.sh start'
ExecStop=/bin/sh -c '/home/tel/Documents/vz/wso2am-2.1.0/wso2am-2.1.0/bin/wso2server.sh stop'
ExecRestart=/bin/sh -c '/home/tel/Documents/vz/wso2am-2.1.0/wso2am-2.1.0/bin/wso2server.sh restart'
PIDFile=/home/tel/Documents/vz/wso2am-2.1.0/wso2am-2.1.0/wso2carbon.pid
User=tel
Group=tel
Type=forking
Restart=always
RestartSec=2
StartLimitInterval=60s
StartLimitBurst=3
StandardOutput=journal

[Install]
WantedBy=multi-user.target

Now when you search for the wso2am process, use the below command.

ps -ef | grep java

Then pick the PID for the wso2am java process and kill it.

kill -9 <wso2_server_PID>

Immediately run

ps -ef | grep java

again and see that the process is not there now. Then within 2 seconds as we have specified RestartSec=2, you will see the wso2 server process is back up and running with a different PID. Then you can make sure that the wso2 instance has respawned on failure.

  • I found this very nice overview of SystemD unit files. It may be helpful to you, too: https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files – Stevel Feb 11 '21 at 02:10