#!/bin/bash

PROG="mmx-console"
PID_PATH="./"
pid=

start() {
	if [ -e "$PID_PATH/$PROG.pid" ]; then
		## Program is running, exit with error.
		echo "Error! $PROG is already running!" 1>&2
		exit 1
	else
		nohup node start.js > mmx-console.out 2>&1& 
		touch "$PID_PATH/$PROG.pid"
		pid=$!
		echo $pid >> $PID_PATH/$PROG.pid
	fi
}

stop() {
	if [ -e "$PID_PATH/$PROG.pid" ]; then
		pid=$(<$PID_PATH/$PROG.pid)
		kill -SIGTERM $pid

		rm "$PID_PATH/$PROG.pid"

		echo "$PROG stopped"
	else
		## Program is not running, exit with error.
		echo "stop:$PROG :  $PROG is not running" 1>&2
	fi
}


case "$1" in
	start)
		start
		exit 0
		;;
	stop)
		stop
		exit 0
		;;
	restart)
		stop
		start
		exit 0
		;;
	**)
		echo "Usage: $0 {start|stop|restart}" 1>&2
		exit 1
		;;
esac

#!/bin/bash

PROG="mmx-console"
PID_PATH="./"
pid=

start() {
	if [ -e "$PID_PATH/$PROG.pid" ]; then
		## Program is running, exit with error.
		echo "Error! $PROG is already running or you have a stale pid file. If $PROG is not running delete $PID_PATH/$PROG.pid file and restart" 1>&2
		exit 1
	else
		nohup node start.js > mmx-console.out 2>&1& 
		touch "$PID_PATH/$PROG.pid"
		pid=$!
		echo $pid >> $PID_PATH/$PROG.pid
	fi
}

stop() {
	if [ -e "$PID_PATH/$PROG.pid" ]; then
		pid=$(<$PID_PATH/$PROG.pid)
		kill -SIGTERM $pid

		rm "$PID_PATH/$PROG.pid"

		echo "$PROG stopped"
	else
		## Program is not running, exit with error.
		echo "stop:$PROG :  $PROG is not running" 1>&2
	fi
}


case "$1" in
	start)
		start
		exit 0
		;;
	stop)
		stop
		exit 0
		;;
	restart)
		stop
		start
		exit 0
		;;
	**)
		echo "Usage: $0 {start|stop|restart}" 1>&2
		exit 1
		;;
esac

Change error message if pid file exists but process does not
Change error message if pid file exists but process does not


Former-commit-id: 490461253979b3e79a55f93a7630425fcd9c8934
Former-commit-id: c2d87fa7bfcf3a3852bbc5219e82433fcdb2b81a
Former-commit-id: 92874d6f99ddc8810fcd759fcd34215f9b6b4f87
Former-commit-id: 3dcdbc4624e23717c40ac2e2ff05531545e8dedd