keep services up 2 1

keep services up 2

function finish {
    # re-start service
    sudo service mongdb start
trap finish EXIT
# Stop the mongod instance
sudo service mongdb stop
# (If mongod is configured to fork, e.g. as part of a replica set, you
# may instead need to do "sudo killall --wait /usr/bin/mongod".)

Here is what the above code is Doing:
1. It’s creating a function called finish that will be called when the script exits.
2. It’s using the trap command to tell the shell to call the finish function when the script exits.
3. It’s stopping the mongodb service.
4. It’s starting the mongodb service.

Similar Posts