Init Script not running from PWD

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have installed gunicorn webserver and make gunicorn virtualenv init.d script but when i run service gunicorn start service from my project directory it works well, But when my present working directory changed such as /root or anyother directory it gives me error. I have edited init script and add following command at start of that script cd /root/demoproject/ script runs from any working directory. What else will be the actual solution other that adding cd /root/demoproject/ command in init script ?







share|improve this question

























    up vote
    0
    down vote

    favorite












    I have installed gunicorn webserver and make gunicorn virtualenv init.d script but when i run service gunicorn start service from my project directory it works well, But when my present working directory changed such as /root or anyother directory it gives me error. I have edited init script and add following command at start of that script cd /root/demoproject/ script runs from any working directory. What else will be the actual solution other that adding cd /root/demoproject/ command in init script ?







    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have installed gunicorn webserver and make gunicorn virtualenv init.d script but when i run service gunicorn start service from my project directory it works well, But when my present working directory changed such as /root or anyother directory it gives me error. I have edited init script and add following command at start of that script cd /root/demoproject/ script runs from any working directory. What else will be the actual solution other that adding cd /root/demoproject/ command in init script ?







      share|improve this question













      I have installed gunicorn webserver and make gunicorn virtualenv init.d script but when i run service gunicorn start service from my project directory it works well, But when my present working directory changed such as /root or anyother directory it gives me error. I have edited init script and add following command at start of that script cd /root/demoproject/ script runs from any working directory. What else will be the actual solution other that adding cd /root/demoproject/ command in init script ?









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jun 27 at 8:10
























      asked Jun 27 at 7:56









      blaCkninJa

      120111




      120111




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          There is nothing wrong with letting the script change its working directory, if it needs to be run with a specific working directory (due to it using relative paths, or whatever it does).



          The only thing that one may want to do is to exit with a non-zero exit status if the cd failed:



          cd /root/demoproject || exit 1


          You may also change directory in the script depending on the value of an environment variable:



          cd "$MY_WORK_DIR:-/root/demoproject" || exit 1


          This would change working directory to the directory given by MY_WORK_DIR, but would default to /root/demoproject if this variable is empty or unset.






          share|improve this answer























          • I have edited the question, Actually i want to know Is there anything possible to make env variable instead of adding cd /root/demoproject/ in init script ?
            – blaCkninJa
            Jun 27 at 8:12










          • @blaCkninJa See updated answer.
            – Kusalananda
            Jun 27 at 8:35










          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          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%2f452165%2finit-script-not-running-from-pwd%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          There is nothing wrong with letting the script change its working directory, if it needs to be run with a specific working directory (due to it using relative paths, or whatever it does).



          The only thing that one may want to do is to exit with a non-zero exit status if the cd failed:



          cd /root/demoproject || exit 1


          You may also change directory in the script depending on the value of an environment variable:



          cd "$MY_WORK_DIR:-/root/demoproject" || exit 1


          This would change working directory to the directory given by MY_WORK_DIR, but would default to /root/demoproject if this variable is empty or unset.






          share|improve this answer























          • I have edited the question, Actually i want to know Is there anything possible to make env variable instead of adding cd /root/demoproject/ in init script ?
            – blaCkninJa
            Jun 27 at 8:12










          • @blaCkninJa See updated answer.
            – Kusalananda
            Jun 27 at 8:35














          up vote
          0
          down vote













          There is nothing wrong with letting the script change its working directory, if it needs to be run with a specific working directory (due to it using relative paths, or whatever it does).



          The only thing that one may want to do is to exit with a non-zero exit status if the cd failed:



          cd /root/demoproject || exit 1


          You may also change directory in the script depending on the value of an environment variable:



          cd "$MY_WORK_DIR:-/root/demoproject" || exit 1


          This would change working directory to the directory given by MY_WORK_DIR, but would default to /root/demoproject if this variable is empty or unset.






          share|improve this answer























          • I have edited the question, Actually i want to know Is there anything possible to make env variable instead of adding cd /root/demoproject/ in init script ?
            – blaCkninJa
            Jun 27 at 8:12










          • @blaCkninJa See updated answer.
            – Kusalananda
            Jun 27 at 8:35












          up vote
          0
          down vote










          up vote
          0
          down vote









          There is nothing wrong with letting the script change its working directory, if it needs to be run with a specific working directory (due to it using relative paths, or whatever it does).



          The only thing that one may want to do is to exit with a non-zero exit status if the cd failed:



          cd /root/demoproject || exit 1


          You may also change directory in the script depending on the value of an environment variable:



          cd "$MY_WORK_DIR:-/root/demoproject" || exit 1


          This would change working directory to the directory given by MY_WORK_DIR, but would default to /root/demoproject if this variable is empty or unset.






          share|improve this answer















          There is nothing wrong with letting the script change its working directory, if it needs to be run with a specific working directory (due to it using relative paths, or whatever it does).



          The only thing that one may want to do is to exit with a non-zero exit status if the cd failed:



          cd /root/demoproject || exit 1


          You may also change directory in the script depending on the value of an environment variable:



          cd "$MY_WORK_DIR:-/root/demoproject" || exit 1


          This would change working directory to the directory given by MY_WORK_DIR, but would default to /root/demoproject if this variable is empty or unset.







          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited Jun 27 at 8:35


























          answered Jun 27 at 8:00









          Kusalananda

          101k13199312




          101k13199312











          • I have edited the question, Actually i want to know Is there anything possible to make env variable instead of adding cd /root/demoproject/ in init script ?
            – blaCkninJa
            Jun 27 at 8:12










          • @blaCkninJa See updated answer.
            – Kusalananda
            Jun 27 at 8:35
















          • I have edited the question, Actually i want to know Is there anything possible to make env variable instead of adding cd /root/demoproject/ in init script ?
            – blaCkninJa
            Jun 27 at 8:12










          • @blaCkninJa See updated answer.
            – Kusalananda
            Jun 27 at 8:35















          I have edited the question, Actually i want to know Is there anything possible to make env variable instead of adding cd /root/demoproject/ in init script ?
          – blaCkninJa
          Jun 27 at 8:12




          I have edited the question, Actually i want to know Is there anything possible to make env variable instead of adding cd /root/demoproject/ in init script ?
          – blaCkninJa
          Jun 27 at 8:12












          @blaCkninJa See updated answer.
          – Kusalananda
          Jun 27 at 8:35




          @blaCkninJa See updated answer.
          – Kusalananda
          Jun 27 at 8:35












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f452165%2finit-script-not-running-from-pwd%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay