Script get in process multiple times












1















I have a script that starts, kills or restarts several java programs. However, when I execute it, it ends up running multiple multiple times in the background.



This is my script:



#!/bin/bash

export jvmArgs="-jar -Xms1024m -Xmx2048m -Djava.security.egd=file:/dev/../dev/urandom"

function killer () {
app=$1
kill -9 $(ps -ef | grep ${app} | grep -v grep | awk '{print $2}');

}


function start_acolds ()
{
basePath=/path/to/apps/
cd ${basePath}
cd ${basePath}app0 && nohup java ${jvmArgs} app0.jar >/dev/null 2>&1&
cd ${basePath}app1 && nohup java ${jvmArgs} app1.jar >/dev/null 2>&1&
cd ${basePath}app2 && nohup java ${jvmArgs} app2.jar >/dev/null 2>&1&
cd ${basePath}app3 && nohup java ${jvmArgs} app3.jar >/dev/null 2>&1&
cd ${basePath}app4 && nohup java ${jvmArgs} app4.jar >/dev/null 2>&1&
cd ${basePath}app5 && nohup java ${jvmArgs} app5.jar >/dev/null 2>&1&
cd ${basePath}app6 && nohup java ${jvmArgs} app6.jar >/dev/null 2>&1&
cd ${basePath}app7 && nohup java ${jvmArgs} app7.jar >/dev/null 2>&1&
cd ${basePath}app8 && nohup java ${jvmArgs} app8.jar >/dev/null 2>&1&

}
function kill_acolds(){
killer app0.jar
killer app1.jar
killer app2.jar
killer app3.jar
killer app4.jar
killer app5.jar
killer app6.jar
killer app7.jar
killer app8.jar
}
case "$1" in
start)
echo "Iniciando servicios... "
start_acolds
;;
stop)
echo "Deteniendo servicios..."
kill_acolds
;;
restart)
kill_acolds
start_acolds
;;
*)
echo "Modo de empleo: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0


When I execute it, it does its job, and startskills all programs, but then I see this in the output of ps:



user1@UbuntuMachine:/$ ps -ef|grep -v grep|grep acoldp.sh.dc
user1 12241 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
user1 12242 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
user1 12243 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
user1 12244 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
user1 12245 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
user1 12246 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
user1 12247 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
user1 12248 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
user1 12249 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
user1 12252 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
user1 12253 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
user1 12254 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
user1 12257 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
user1 12258 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart


So, why is this getting stuck like this? I mean, it does its job but it bugs me having all that in the background.










share|improve this question





























    1















    I have a script that starts, kills or restarts several java programs. However, when I execute it, it ends up running multiple multiple times in the background.



    This is my script:



    #!/bin/bash

    export jvmArgs="-jar -Xms1024m -Xmx2048m -Djava.security.egd=file:/dev/../dev/urandom"

    function killer () {
    app=$1
    kill -9 $(ps -ef | grep ${app} | grep -v grep | awk '{print $2}');

    }


    function start_acolds ()
    {
    basePath=/path/to/apps/
    cd ${basePath}
    cd ${basePath}app0 && nohup java ${jvmArgs} app0.jar >/dev/null 2>&1&
    cd ${basePath}app1 && nohup java ${jvmArgs} app1.jar >/dev/null 2>&1&
    cd ${basePath}app2 && nohup java ${jvmArgs} app2.jar >/dev/null 2>&1&
    cd ${basePath}app3 && nohup java ${jvmArgs} app3.jar >/dev/null 2>&1&
    cd ${basePath}app4 && nohup java ${jvmArgs} app4.jar >/dev/null 2>&1&
    cd ${basePath}app5 && nohup java ${jvmArgs} app5.jar >/dev/null 2>&1&
    cd ${basePath}app6 && nohup java ${jvmArgs} app6.jar >/dev/null 2>&1&
    cd ${basePath}app7 && nohup java ${jvmArgs} app7.jar >/dev/null 2>&1&
    cd ${basePath}app8 && nohup java ${jvmArgs} app8.jar >/dev/null 2>&1&

    }
    function kill_acolds(){
    killer app0.jar
    killer app1.jar
    killer app2.jar
    killer app3.jar
    killer app4.jar
    killer app5.jar
    killer app6.jar
    killer app7.jar
    killer app8.jar
    }
    case "$1" in
    start)
    echo "Iniciando servicios... "
    start_acolds
    ;;
    stop)
    echo "Deteniendo servicios..."
    kill_acolds
    ;;
    restart)
    kill_acolds
    start_acolds
    ;;
    *)
    echo "Modo de empleo: $0 {start|stop|restart}"
    exit 1
    ;;
    esac
    exit 0


    When I execute it, it does its job, and startskills all programs, but then I see this in the output of ps:



    user1@UbuntuMachine:/$ ps -ef|grep -v grep|grep acoldp.sh.dc
    user1 12241 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
    user1 12242 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
    user1 12243 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
    user1 12244 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
    user1 12245 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
    user1 12246 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
    user1 12247 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
    user1 12248 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
    user1 12249 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
    user1 12252 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
    user1 12253 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
    user1 12254 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
    user1 12257 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
    user1 12258 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart


    So, why is this getting stuck like this? I mean, it does its job but it bugs me having all that in the background.










    share|improve this question



























      1












      1








      1








      I have a script that starts, kills or restarts several java programs. However, when I execute it, it ends up running multiple multiple times in the background.



      This is my script:



      #!/bin/bash

      export jvmArgs="-jar -Xms1024m -Xmx2048m -Djava.security.egd=file:/dev/../dev/urandom"

      function killer () {
      app=$1
      kill -9 $(ps -ef | grep ${app} | grep -v grep | awk '{print $2}');

      }


      function start_acolds ()
      {
      basePath=/path/to/apps/
      cd ${basePath}
      cd ${basePath}app0 && nohup java ${jvmArgs} app0.jar >/dev/null 2>&1&
      cd ${basePath}app1 && nohup java ${jvmArgs} app1.jar >/dev/null 2>&1&
      cd ${basePath}app2 && nohup java ${jvmArgs} app2.jar >/dev/null 2>&1&
      cd ${basePath}app3 && nohup java ${jvmArgs} app3.jar >/dev/null 2>&1&
      cd ${basePath}app4 && nohup java ${jvmArgs} app4.jar >/dev/null 2>&1&
      cd ${basePath}app5 && nohup java ${jvmArgs} app5.jar >/dev/null 2>&1&
      cd ${basePath}app6 && nohup java ${jvmArgs} app6.jar >/dev/null 2>&1&
      cd ${basePath}app7 && nohup java ${jvmArgs} app7.jar >/dev/null 2>&1&
      cd ${basePath}app8 && nohup java ${jvmArgs} app8.jar >/dev/null 2>&1&

      }
      function kill_acolds(){
      killer app0.jar
      killer app1.jar
      killer app2.jar
      killer app3.jar
      killer app4.jar
      killer app5.jar
      killer app6.jar
      killer app7.jar
      killer app8.jar
      }
      case "$1" in
      start)
      echo "Iniciando servicios... "
      start_acolds
      ;;
      stop)
      echo "Deteniendo servicios..."
      kill_acolds
      ;;
      restart)
      kill_acolds
      start_acolds
      ;;
      *)
      echo "Modo de empleo: $0 {start|stop|restart}"
      exit 1
      ;;
      esac
      exit 0


      When I execute it, it does its job, and startskills all programs, but then I see this in the output of ps:



      user1@UbuntuMachine:/$ ps -ef|grep -v grep|grep acoldp.sh.dc
      user1 12241 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12242 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12243 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12244 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12245 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12246 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12247 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12248 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12249 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12252 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12253 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12254 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12257 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12258 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart


      So, why is this getting stuck like this? I mean, it does its job but it bugs me having all that in the background.










      share|improve this question
















      I have a script that starts, kills or restarts several java programs. However, when I execute it, it ends up running multiple multiple times in the background.



      This is my script:



      #!/bin/bash

      export jvmArgs="-jar -Xms1024m -Xmx2048m -Djava.security.egd=file:/dev/../dev/urandom"

      function killer () {
      app=$1
      kill -9 $(ps -ef | grep ${app} | grep -v grep | awk '{print $2}');

      }


      function start_acolds ()
      {
      basePath=/path/to/apps/
      cd ${basePath}
      cd ${basePath}app0 && nohup java ${jvmArgs} app0.jar >/dev/null 2>&1&
      cd ${basePath}app1 && nohup java ${jvmArgs} app1.jar >/dev/null 2>&1&
      cd ${basePath}app2 && nohup java ${jvmArgs} app2.jar >/dev/null 2>&1&
      cd ${basePath}app3 && nohup java ${jvmArgs} app3.jar >/dev/null 2>&1&
      cd ${basePath}app4 && nohup java ${jvmArgs} app4.jar >/dev/null 2>&1&
      cd ${basePath}app5 && nohup java ${jvmArgs} app5.jar >/dev/null 2>&1&
      cd ${basePath}app6 && nohup java ${jvmArgs} app6.jar >/dev/null 2>&1&
      cd ${basePath}app7 && nohup java ${jvmArgs} app7.jar >/dev/null 2>&1&
      cd ${basePath}app8 && nohup java ${jvmArgs} app8.jar >/dev/null 2>&1&

      }
      function kill_acolds(){
      killer app0.jar
      killer app1.jar
      killer app2.jar
      killer app3.jar
      killer app4.jar
      killer app5.jar
      killer app6.jar
      killer app7.jar
      killer app8.jar
      }
      case "$1" in
      start)
      echo "Iniciando servicios... "
      start_acolds
      ;;
      stop)
      echo "Deteniendo servicios..."
      kill_acolds
      ;;
      restart)
      kill_acolds
      start_acolds
      ;;
      *)
      echo "Modo de empleo: $0 {start|stop|restart}"
      exit 1
      ;;
      esac
      exit 0


      When I execute it, it does its job, and startskills all programs, but then I see this in the output of ps:



      user1@UbuntuMachine:/$ ps -ef|grep -v grep|grep acoldp.sh.dc
      user1 12241 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12242 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12243 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12244 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12245 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12246 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12247 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12248 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12249 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12252 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12253 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12254 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12257 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart
      user1 12258 1 0 11:24 pts/1 00:00:00 /bin/bash ./acoldp.sh.dc restart


      So, why is this getting stuck like this? I mean, it does its job but it bugs me having all that in the background.







      bash shell-script command-line nohup






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 7 at 16:55









      terdon

      129k32253428




      129k32253428










      asked Jan 7 at 16:24









      Danilo CarenaDanilo Carena

      63




      63






















          0






          active

          oldest

          votes











          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%2f493029%2fscript-get-in-process-multiple-times%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f493029%2fscript-get-in-process-multiple-times%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

          Morgemoulin

          Scott Moir

          Souastre