how to run “play start” as a linux service












1















I want deploy a play framework web application from source, and run "play start" to start the application.



I wrote a startup script in /etc/init.d/ which execute "daemon play start" when service start, but the service start command did not return. I guess it's because play start is waiting for me to give him a Ctrl+D. "nohup" can fix it, but with "nohup", I have to run "kill -9 xxx" to stop the application, which is not what I like.



What's the best way to run a play framework application from source as a linux startup service.



Thanks a lot.










share|improve this question














bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






migrated from stackoverflow.com Jan 10 '16 at 19:03


This question came from our site for professional and enthusiast programmers.























    1















    I want deploy a play framework web application from source, and run "play start" to start the application.



    I wrote a startup script in /etc/init.d/ which execute "daemon play start" when service start, but the service start command did not return. I guess it's because play start is waiting for me to give him a Ctrl+D. "nohup" can fix it, but with "nohup", I have to run "kill -9 xxx" to stop the application, which is not what I like.



    What's the best way to run a play framework application from source as a linux startup service.



    Thanks a lot.










    share|improve this question














    bumped to the homepage by Community 9 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






    migrated from stackoverflow.com Jan 10 '16 at 19:03


    This question came from our site for professional and enthusiast programmers.





















      1












      1








      1








      I want deploy a play framework web application from source, and run "play start" to start the application.



      I wrote a startup script in /etc/init.d/ which execute "daemon play start" when service start, but the service start command did not return. I guess it's because play start is waiting for me to give him a Ctrl+D. "nohup" can fix it, but with "nohup", I have to run "kill -9 xxx" to stop the application, which is not what I like.



      What's the best way to run a play framework application from source as a linux startup service.



      Thanks a lot.










      share|improve this question














      I want deploy a play framework web application from source, and run "play start" to start the application.



      I wrote a startup script in /etc/init.d/ which execute "daemon play start" when service start, but the service start command did not return. I guess it's because play start is waiting for me to give him a Ctrl+D. "nohup" can fix it, but with "nohup", I have to run "kill -9 xxx" to stop the application, which is not what I like.



      What's the best way to run a play framework application from source as a linux startup service.



      Thanks a lot.







      linux






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 30 '15 at 5:07







      Ray












      bumped to the homepage by Community 9 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 9 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






      migrated from stackoverflow.com Jan 10 '16 at 19:03


      This question came from our site for professional and enthusiast programmers.









      migrated from stackoverflow.com Jan 10 '16 at 19:03


      This question came from our site for professional and enthusiast programmers.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Here is simple init.d script, which:




          • START: recompiles (if needed) and starts application in background, only if application wasn't already started

          • STOP: kills app


          Read comments in code carefully.



          #!/bin/sh
          # /etc/init.d/playapp

          # Play project directory is in /var/play/playapp/www, not directly in SDIR
          SDIR="/var/play/playapp"

          # The following part always gets executed.
          echo "PLAYAPP Service"

          # The following part carries out specific functions depending on arguments.
          case "$1" in
          start)
          echo " * Starting PLAYAPP Service"

          if [ -f ${SDIR}/www/target/universal/stage/RUNNING_PID ]
          then
          PID=$(cat ${SDIR}www/target/universal/stage/RUNNING_PID)

          if ps -p $PID > /dev/null
          then
          echo " service already running ($PID)"
          exit 1
          fi
          fi

          cd ${SDIR}/www

          # REPLACE "PROJECT_NAME" with your project name

          if [ ! -f ${SDIR}/www/target/universal/stage/bin/PROJECT_NAME ]
          then
          echo " recompiling..."

          # REPLACE path to your play command
          /var/play-install/play/play clean compile stage
          fi

          echo " starting..."
          nohup ./target/universal/stage/bin/PROJECT_NAME -Dhttp.port=9900 -Dconfig.file=/var/play/playapp/www/conf/application-prod.conf > application.log 2>&1&
          ;;
          stop)
          echo " * Stopping PLAYAPP Service"

          if [ ! -f ${SDIR}/www/target/universal/stage/RUNNING_PID ]
          then
          echo " nothing to stop"
          exit 1;
          fi

          kill -TERM $(cat ${SDIR}/www/target/universal/stage/RUNNING_PID)
          ;;
          *)
          echo "Usage: /etc/init.d/playapp {start|stop}"
          exit 1
          ;;
          esac

          exit 0





          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f254451%2fhow-to-run-play-start-as-a-linux-service%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown
























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Here is simple init.d script, which:




            • START: recompiles (if needed) and starts application in background, only if application wasn't already started

            • STOP: kills app


            Read comments in code carefully.



            #!/bin/sh
            # /etc/init.d/playapp

            # Play project directory is in /var/play/playapp/www, not directly in SDIR
            SDIR="/var/play/playapp"

            # The following part always gets executed.
            echo "PLAYAPP Service"

            # The following part carries out specific functions depending on arguments.
            case "$1" in
            start)
            echo " * Starting PLAYAPP Service"

            if [ -f ${SDIR}/www/target/universal/stage/RUNNING_PID ]
            then
            PID=$(cat ${SDIR}www/target/universal/stage/RUNNING_PID)

            if ps -p $PID > /dev/null
            then
            echo " service already running ($PID)"
            exit 1
            fi
            fi

            cd ${SDIR}/www

            # REPLACE "PROJECT_NAME" with your project name

            if [ ! -f ${SDIR}/www/target/universal/stage/bin/PROJECT_NAME ]
            then
            echo " recompiling..."

            # REPLACE path to your play command
            /var/play-install/play/play clean compile stage
            fi

            echo " starting..."
            nohup ./target/universal/stage/bin/PROJECT_NAME -Dhttp.port=9900 -Dconfig.file=/var/play/playapp/www/conf/application-prod.conf > application.log 2>&1&
            ;;
            stop)
            echo " * Stopping PLAYAPP Service"

            if [ ! -f ${SDIR}/www/target/universal/stage/RUNNING_PID ]
            then
            echo " nothing to stop"
            exit 1;
            fi

            kill -TERM $(cat ${SDIR}/www/target/universal/stage/RUNNING_PID)
            ;;
            *)
            echo "Usage: /etc/init.d/playapp {start|stop}"
            exit 1
            ;;
            esac

            exit 0





            share|improve this answer




























              0














              Here is simple init.d script, which:




              • START: recompiles (if needed) and starts application in background, only if application wasn't already started

              • STOP: kills app


              Read comments in code carefully.



              #!/bin/sh
              # /etc/init.d/playapp

              # Play project directory is in /var/play/playapp/www, not directly in SDIR
              SDIR="/var/play/playapp"

              # The following part always gets executed.
              echo "PLAYAPP Service"

              # The following part carries out specific functions depending on arguments.
              case "$1" in
              start)
              echo " * Starting PLAYAPP Service"

              if [ -f ${SDIR}/www/target/universal/stage/RUNNING_PID ]
              then
              PID=$(cat ${SDIR}www/target/universal/stage/RUNNING_PID)

              if ps -p $PID > /dev/null
              then
              echo " service already running ($PID)"
              exit 1
              fi
              fi

              cd ${SDIR}/www

              # REPLACE "PROJECT_NAME" with your project name

              if [ ! -f ${SDIR}/www/target/universal/stage/bin/PROJECT_NAME ]
              then
              echo " recompiling..."

              # REPLACE path to your play command
              /var/play-install/play/play clean compile stage
              fi

              echo " starting..."
              nohup ./target/universal/stage/bin/PROJECT_NAME -Dhttp.port=9900 -Dconfig.file=/var/play/playapp/www/conf/application-prod.conf > application.log 2>&1&
              ;;
              stop)
              echo " * Stopping PLAYAPP Service"

              if [ ! -f ${SDIR}/www/target/universal/stage/RUNNING_PID ]
              then
              echo " nothing to stop"
              exit 1;
              fi

              kill -TERM $(cat ${SDIR}/www/target/universal/stage/RUNNING_PID)
              ;;
              *)
              echo "Usage: /etc/init.d/playapp {start|stop}"
              exit 1
              ;;
              esac

              exit 0





              share|improve this answer


























                0












                0








                0







                Here is simple init.d script, which:




                • START: recompiles (if needed) and starts application in background, only if application wasn't already started

                • STOP: kills app


                Read comments in code carefully.



                #!/bin/sh
                # /etc/init.d/playapp

                # Play project directory is in /var/play/playapp/www, not directly in SDIR
                SDIR="/var/play/playapp"

                # The following part always gets executed.
                echo "PLAYAPP Service"

                # The following part carries out specific functions depending on arguments.
                case "$1" in
                start)
                echo " * Starting PLAYAPP Service"

                if [ -f ${SDIR}/www/target/universal/stage/RUNNING_PID ]
                then
                PID=$(cat ${SDIR}www/target/universal/stage/RUNNING_PID)

                if ps -p $PID > /dev/null
                then
                echo " service already running ($PID)"
                exit 1
                fi
                fi

                cd ${SDIR}/www

                # REPLACE "PROJECT_NAME" with your project name

                if [ ! -f ${SDIR}/www/target/universal/stage/bin/PROJECT_NAME ]
                then
                echo " recompiling..."

                # REPLACE path to your play command
                /var/play-install/play/play clean compile stage
                fi

                echo " starting..."
                nohup ./target/universal/stage/bin/PROJECT_NAME -Dhttp.port=9900 -Dconfig.file=/var/play/playapp/www/conf/application-prod.conf > application.log 2>&1&
                ;;
                stop)
                echo " * Stopping PLAYAPP Service"

                if [ ! -f ${SDIR}/www/target/universal/stage/RUNNING_PID ]
                then
                echo " nothing to stop"
                exit 1;
                fi

                kill -TERM $(cat ${SDIR}/www/target/universal/stage/RUNNING_PID)
                ;;
                *)
                echo "Usage: /etc/init.d/playapp {start|stop}"
                exit 1
                ;;
                esac

                exit 0





                share|improve this answer













                Here is simple init.d script, which:




                • START: recompiles (if needed) and starts application in background, only if application wasn't already started

                • STOP: kills app


                Read comments in code carefully.



                #!/bin/sh
                # /etc/init.d/playapp

                # Play project directory is in /var/play/playapp/www, not directly in SDIR
                SDIR="/var/play/playapp"

                # The following part always gets executed.
                echo "PLAYAPP Service"

                # The following part carries out specific functions depending on arguments.
                case "$1" in
                start)
                echo " * Starting PLAYAPP Service"

                if [ -f ${SDIR}/www/target/universal/stage/RUNNING_PID ]
                then
                PID=$(cat ${SDIR}www/target/universal/stage/RUNNING_PID)

                if ps -p $PID > /dev/null
                then
                echo " service already running ($PID)"
                exit 1
                fi
                fi

                cd ${SDIR}/www

                # REPLACE "PROJECT_NAME" with your project name

                if [ ! -f ${SDIR}/www/target/universal/stage/bin/PROJECT_NAME ]
                then
                echo " recompiling..."

                # REPLACE path to your play command
                /var/play-install/play/play clean compile stage
                fi

                echo " starting..."
                nohup ./target/universal/stage/bin/PROJECT_NAME -Dhttp.port=9900 -Dconfig.file=/var/play/playapp/www/conf/application-prod.conf > application.log 2>&1&
                ;;
                stop)
                echo " * Stopping PLAYAPP Service"

                if [ ! -f ${SDIR}/www/target/universal/stage/RUNNING_PID ]
                then
                echo " nothing to stop"
                exit 1;
                fi

                kill -TERM $(cat ${SDIR}/www/target/universal/stage/RUNNING_PID)
                ;;
                *)
                echo "Usage: /etc/init.d/playapp {start|stop}"
                exit 1
                ;;
                esac

                exit 0






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 4 '16 at 19:17







                Pawel Hawro





































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f254451%2fhow-to-run-play-start-as-a-linux-service%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Loup dans la culture

                    How to solve the problem of ntp “Unable to contact time server” from KDE?

                    ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux