System wide variables for both init scripts and system?












0















I created my own init scripts that use variables:



#! /bin/sh

case "$1" in
start)
echo "Starting Public API"
sudo -u techops sh ${JBOSS_HOME_PUBLIC_API}/bin/standalone.sh > ${PUBLICAPI_LOGGING_PATH} &
;;
stop)
echo "Stopping Public API"
sudo -u techops sh ${JBOSS_HOME_PUBLIC_API}/bin/jboss-cli.sh --connect --controller=localhost:$((9990 + $PUBLICAPI_PORT_OFFSET)) command=:shutdown > ${PUBLICAPI_LOGGING_PATH} &
;;
*)
echo "Usage: /etc/init.d/publicapi {start|stop}"
exit 1
;;
esac

exit 0


The variables are defined in /etc/environment and looks so:



PUBLICAPI_PORT_OFFSET=0
PUBLICAPI_LOGGING_PATH=/var/log/publicapi/publicapi.log
JBOSS_HOME_PUBLIC_API=/opt/publicapi


...and work after login, when I start and stop the init script manually, but they didn't work for the startup init scripts (which are symbolic links to /etc/init.d/publicapi in /etc/rc2.d/, /etc/rc5.d/, /etc/rc6.d/). The startup crashes then, because the variables are unknown.



I was able to fix this by executing systemctl edit publicapi which created a file /etc/systemd/system/publicapi.service.d/local.conf which looks like this after I edited it:



[Unit]
Description=Public API startup script
Documentation=no documentation

[Service]
Environment="JBOSS_HOME_PUBLIC_API=/opt/publicapi"
Environment="PUBLICAPI_PORT_OFFSET=0"
Environment="PUBLICAPI_LOGGING_PATH=/var/log/publicapi/publicapi.log"


when I reboot, the startup of the init script works.
But now I have a strange situation:
I always need to define the variable both in /etc/systemd/system/publicapi.service.d/local.conf and in /etc/environment. The init script startup crashes if one of each is missing.
What is the scope of /etc/systemd/system/publicapi.service.d/local.conf (since the values are obviously gone after login)? I don't understand why it crashes when the variables from /etc/environment are missing and how can I define the variables only once globally?










share|improve this question



























    0















    I created my own init scripts that use variables:



    #! /bin/sh

    case "$1" in
    start)
    echo "Starting Public API"
    sudo -u techops sh ${JBOSS_HOME_PUBLIC_API}/bin/standalone.sh > ${PUBLICAPI_LOGGING_PATH} &
    ;;
    stop)
    echo "Stopping Public API"
    sudo -u techops sh ${JBOSS_HOME_PUBLIC_API}/bin/jboss-cli.sh --connect --controller=localhost:$((9990 + $PUBLICAPI_PORT_OFFSET)) command=:shutdown > ${PUBLICAPI_LOGGING_PATH} &
    ;;
    *)
    echo "Usage: /etc/init.d/publicapi {start|stop}"
    exit 1
    ;;
    esac

    exit 0


    The variables are defined in /etc/environment and looks so:



    PUBLICAPI_PORT_OFFSET=0
    PUBLICAPI_LOGGING_PATH=/var/log/publicapi/publicapi.log
    JBOSS_HOME_PUBLIC_API=/opt/publicapi


    ...and work after login, when I start and stop the init script manually, but they didn't work for the startup init scripts (which are symbolic links to /etc/init.d/publicapi in /etc/rc2.d/, /etc/rc5.d/, /etc/rc6.d/). The startup crashes then, because the variables are unknown.



    I was able to fix this by executing systemctl edit publicapi which created a file /etc/systemd/system/publicapi.service.d/local.conf which looks like this after I edited it:



    [Unit]
    Description=Public API startup script
    Documentation=no documentation

    [Service]
    Environment="JBOSS_HOME_PUBLIC_API=/opt/publicapi"
    Environment="PUBLICAPI_PORT_OFFSET=0"
    Environment="PUBLICAPI_LOGGING_PATH=/var/log/publicapi/publicapi.log"


    when I reboot, the startup of the init script works.
    But now I have a strange situation:
    I always need to define the variable both in /etc/systemd/system/publicapi.service.d/local.conf and in /etc/environment. The init script startup crashes if one of each is missing.
    What is the scope of /etc/systemd/system/publicapi.service.d/local.conf (since the values are obviously gone after login)? I don't understand why it crashes when the variables from /etc/environment are missing and how can I define the variables only once globally?










    share|improve this question

























      0












      0








      0








      I created my own init scripts that use variables:



      #! /bin/sh

      case "$1" in
      start)
      echo "Starting Public API"
      sudo -u techops sh ${JBOSS_HOME_PUBLIC_API}/bin/standalone.sh > ${PUBLICAPI_LOGGING_PATH} &
      ;;
      stop)
      echo "Stopping Public API"
      sudo -u techops sh ${JBOSS_HOME_PUBLIC_API}/bin/jboss-cli.sh --connect --controller=localhost:$((9990 + $PUBLICAPI_PORT_OFFSET)) command=:shutdown > ${PUBLICAPI_LOGGING_PATH} &
      ;;
      *)
      echo "Usage: /etc/init.d/publicapi {start|stop}"
      exit 1
      ;;
      esac

      exit 0


      The variables are defined in /etc/environment and looks so:



      PUBLICAPI_PORT_OFFSET=0
      PUBLICAPI_LOGGING_PATH=/var/log/publicapi/publicapi.log
      JBOSS_HOME_PUBLIC_API=/opt/publicapi


      ...and work after login, when I start and stop the init script manually, but they didn't work for the startup init scripts (which are symbolic links to /etc/init.d/publicapi in /etc/rc2.d/, /etc/rc5.d/, /etc/rc6.d/). The startup crashes then, because the variables are unknown.



      I was able to fix this by executing systemctl edit publicapi which created a file /etc/systemd/system/publicapi.service.d/local.conf which looks like this after I edited it:



      [Unit]
      Description=Public API startup script
      Documentation=no documentation

      [Service]
      Environment="JBOSS_HOME_PUBLIC_API=/opt/publicapi"
      Environment="PUBLICAPI_PORT_OFFSET=0"
      Environment="PUBLICAPI_LOGGING_PATH=/var/log/publicapi/publicapi.log"


      when I reboot, the startup of the init script works.
      But now I have a strange situation:
      I always need to define the variable both in /etc/systemd/system/publicapi.service.d/local.conf and in /etc/environment. The init script startup crashes if one of each is missing.
      What is the scope of /etc/systemd/system/publicapi.service.d/local.conf (since the values are obviously gone after login)? I don't understand why it crashes when the variables from /etc/environment are missing and how can I define the variables only once globally?










      share|improve this question














      I created my own init scripts that use variables:



      #! /bin/sh

      case "$1" in
      start)
      echo "Starting Public API"
      sudo -u techops sh ${JBOSS_HOME_PUBLIC_API}/bin/standalone.sh > ${PUBLICAPI_LOGGING_PATH} &
      ;;
      stop)
      echo "Stopping Public API"
      sudo -u techops sh ${JBOSS_HOME_PUBLIC_API}/bin/jboss-cli.sh --connect --controller=localhost:$((9990 + $PUBLICAPI_PORT_OFFSET)) command=:shutdown > ${PUBLICAPI_LOGGING_PATH} &
      ;;
      *)
      echo "Usage: /etc/init.d/publicapi {start|stop}"
      exit 1
      ;;
      esac

      exit 0


      The variables are defined in /etc/environment and looks so:



      PUBLICAPI_PORT_OFFSET=0
      PUBLICAPI_LOGGING_PATH=/var/log/publicapi/publicapi.log
      JBOSS_HOME_PUBLIC_API=/opt/publicapi


      ...and work after login, when I start and stop the init script manually, but they didn't work for the startup init scripts (which are symbolic links to /etc/init.d/publicapi in /etc/rc2.d/, /etc/rc5.d/, /etc/rc6.d/). The startup crashes then, because the variables are unknown.



      I was able to fix this by executing systemctl edit publicapi which created a file /etc/systemd/system/publicapi.service.d/local.conf which looks like this after I edited it:



      [Unit]
      Description=Public API startup script
      Documentation=no documentation

      [Service]
      Environment="JBOSS_HOME_PUBLIC_API=/opt/publicapi"
      Environment="PUBLICAPI_PORT_OFFSET=0"
      Environment="PUBLICAPI_LOGGING_PATH=/var/log/publicapi/publicapi.log"


      when I reboot, the startup of the init script works.
      But now I have a strange situation:
      I always need to define the variable both in /etc/systemd/system/publicapi.service.d/local.conf and in /etc/environment. The init script startup crashes if one of each is missing.
      What is the scope of /etc/systemd/system/publicapi.service.d/local.conf (since the values are obviously gone after login)? I don't understand why it crashes when the variables from /etc/environment are missing and how can I define the variables only once globally?







      bash scripts systemd upstart environment-variables






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 9 hours ago









      BevorBevor

      218210




      218210






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "89"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2faskubuntu.com%2fquestions%2f1109727%2fsystem-wide-variables-for-both-init-scripts-and-system%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 Ask Ubuntu!


          • 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%2faskubuntu.com%2fquestions%2f1109727%2fsystem-wide-variables-for-both-init-scripts-and-system%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

          GameSpot

          connect to host localhost port 22: Connection refused

          Getting a Wifi WPA2 wifi connection