关于linux环境下 启动java程序,redis ;shell脚本

#!/bin/sh
#chkconfig: 345 86 14
#description: Startup and shutdown script for server.jar
 
PIDFILE=/var/run/java.pid
SERVER=./server.jar
ARGS="-Xms2g -Xmx2g -Xmn2g -Xss128k -XX:MaxPermSize=64m -XX:-UseParallelGC -XX:+UseParallelOldGC -XX:ParallelGCThreads=4 -XX:+UseConcMarkSweepGC -XX:MaxTenuringThreshold=30 -XX:SurvivorRatio=6"
 
start()
{
	if test -e $SERVER
	then
		echo -e "Starting $SERVER"
		if java -jar $SERVER $ARGS >/dev/null 2>&1 & 
		then
			echo $! > $PIDFILE
			echo -e "server start OK"
		else
			echo -e "server start failed"
		fi
	else
		echo -e "Couldn't find server.jar"
	fi
}
 
stop()
{
         if test -e $PIDFILE
         then
                   echo -e "Stopping server"
                   if kill `cat $PIDFILE`
                   then
                            echo -e "server stop OK"
                   else
	                    echo -e "server stop faild"
                   fi
         else
                   echo -e "No server running"
         fi
}
 
restart()
{
    echo -e "Restarting server"
    stop
    start
}

case $1 in
         start)
                start
        ;;
         stop)
        	stop
        ;;
         restart)
        	restart
        ;;
         *)
        	echo "Usage: $SCRIPTNAME {start|stop|restart|list}" >&2
        exit 1
        ;;
esac
exit 0
#!/bin/sh
#chkconfig: 345 86 14
#description: Startup and shutdown script for Redis
 
PROGDIR=/root/redis-2.8.3/src
PROGNAME=redis-server
DAEMON=$PROGDIR/$PROGNAME
CONFIG=/root/redis-2.8.3/redis.conf
PIDFILE=/var/run/redis.pid
DESC="redis daemon"
SCRIPTNAME=/etc/init.d/redisd
 
start()
{
         if test -x $DAEMON
         then
        echo -e "Starting $DESC: $PROGNAME"
                   if $DAEMON $CONFIG > /dev/null 2>&1 &
                   then
                            echo -e "OK"
                   else
                            echo -e "failed"
                   fi
         else
                   echo -e "Couldn't find Redis Server ($DAEMON)"
         fi
}
 
stop()
{
         if test -e $PIDFILE
         then
                   echo -e "Stopping $DESC: $PROGNAME"
                   if kill `cat $PIDFILE`
                   then
                            echo -e "OK"
                   else
                            echo -e "failed"
                   fi
         else
                   echo -e "No Redis Server ($DAEMON) running"
         fi
}
 
restart()
{
    echo -e "Restarting $DESC: $PROGNAME"
    stop
         start
}
 
list()
{
         ps aux | grep $PROGNAME
}
 
case $1 in
         start)
                   start
        ;;
         stop)
        stop
        ;;
         restart)
        restart
        ;;
         list)
        list
        ;;
 
         *)
        echo "Usage: $SCRIPTNAME {start|stop|restart|list}" >&2
        exit 1
        ;;
esac
exit 0


你可能感兴趣的:(关于linux环境下 启动java程序,redis ;shell脚本)