service nginx start

    1. cd /etc/rc.d/init.d
    1. chmod +x codegen
    1. chkconfig --add codegen
    2. chkconfig codegen on

    off: 关

    1. #!/bin/sh
    2. # chkconfig: 2345 55 25
    3. JARPATH=/www/wwwroot/codegen.hntool.vip/
    4. JARNAME=code-generator.jar
    5. EXEC=`nohup /usr/java/jdk1.8.0_251/bin/java -Xmx256m -Xms256m -jar ${JARPATH}${JARNAME} >> ${JARPATH}log.out 2>&1 &`
    6. PIDFILE=/www/wwwroot/codegen.hntool.vip/codegen.pid
    7. codegen_start(){
    8. if [ -f $PIDFILE ]; then
    9. ps -p $(cat ${PIDFILE}) > /dev/null 2>&1
    10. if [ $? -ne "0" ]; then
    11. rm -f ${PIDFILE}
    12. else
    13. echo "codegen is running! ($(cat ${PIDFILE}))"
    14. exit 0
    15. fi
    16. fi
    17. echo "Starting codegen server..."
    18. $EXEC
    19. echo $!> ${PIDFILE}
    20. echo "Starting codegen success!"
    21. }
    22. codegen_status(){
    23. if [ -f $PIDFILE ]; then
    24. ps -p $(cat ${PIDFILE}) > /dev/null 2>&1
    25. if [ $? -ne "0" ]; then
    26. echo "codegen is not running, buy pid file is exits ${PIDFILE}"
    27. exit 1
    28. else
    29. echo "codegen is running! ($(cat ${PIDFILE}))"
    30. exit 0
    31. fi
    32. else
    33. echo "codegen is stopped"
    34. exit 0
    35. fi
    36. }
    37. codegen_stop(){
    38. echo "Stopping ..."
    39. sleep 1
    40. if [ -f $PIDFILE ];then
    41. kill -9 `ps -ef|grep $JARNAME|grep -v grep|grep -v stop|awk '{print $2}'`
    42. fi
    43. rm -f ${PIDFILE}
    44. echo "codegen stopped"
    45. }
    46. case "$1" in
    47. start)
    48. codegen_start
    49. ;;
    50. stop)
    51. codegen_stop
    52. ;;
    53. status)
    54. codegen_status
    55. ;;
    56. restart|reload)
    57. codegen_stop
    58. sleep 0.3
    59. codegen_start
    60. ;;
    61. *)
    62. echo "Please use start or stop as first argument"
    63. ;;
    64. esac