The code below shows the upstart service configuration file
/etc/init/nodemanager.conf. You execute the
yarn-daemon.sh start nodemanager script as pre-start hook, and
yarn-daemon.sh stop nodemanager as post-stop hook. This starts the actual nodemanager instance.
The script checks if nodemanager is up. If nodemanager is down, the script exits. This signals upstart that the service has gone down and has to be restarted.
start on startup
stop on shutdown
# actually start nodemanager
pre-start exec opt/hadoop/current/sbin/yarn-daemon.sh start nodemanager
# upstart executes this script. If this script exits, upstart respawns the service
# cannot just excecute *-daemon.sh here, because the actual daemon script excecutes after start
# and upstart thinks service is stopped so respawns *-daemon.sh constantly.
while jps | grep -q NodeManager; do
post-stop exec /opt/hadoop/current/sbin/yarn-daemon.sh stop nodemanager