Deployed digitalocean app isn't reading environment variables Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Setting environment variables on OS XRead environment variables in Node.jsHow to access environment variable values?List all environment variables from command line?How to set environment variables in PythonHow do I delete an exported environment variable?Set environment variables on Mac OS X LionAdding directory to PATH Environment Variable in WindowsSetting Environment Variables for Node to retrieveHow do I pass environment variables to Docker containers?

One-one communication

Statistical analysis applied to methods coming out of Machine Learning

Should man-made satellites feature an intelligent inverted "cow catcher"?

Baking rewards as operations

Twin's vs. Twins'

Sally's older brother

Weaponising the Grasp-at-a-Distance spell

Why is there so little support for joining EFTA in the British parliament?

How do Java 8 default methods hеlp with lambdas?

Can gravitational waves pass through a black hole?

How to ask rejected full-time candidates to apply to teach individual courses?

Did any compiler fully use 80-bit floating point?

Keep at all times, the minus sign above aligned with minus sign below

An isoperimetric-type inequality inside a cube

By what mechanism was the 2017 UK General Election called?

What was the last profitable war?

NIntegrate on a solution of a matrix ODE

Russian equivalents of おしゃれは足元から (Every good outfit starts with the shoes)

How does TikZ render an arc?

Is the time—manner—place ordering of adverbials an oversimplification?

Noise in Eigenvalues plot

Problem with display of presentation

Did pre-Columbian Americans know the spherical shape of the Earth?

Determine whether an integer is a palindrome



Deployed digitalocean app isn't reading environment variables



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Setting environment variables on OS XRead environment variables in Node.jsHow to access environment variable values?List all environment variables from command line?How to set environment variables in PythonHow do I delete an exported environment variable?Set environment variables on Mac OS X LionAdding directory to PATH Environment Variable in WindowsSetting Environment Variables for Node to retrieveHow do I pass environment variables to Docker containers?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have deployed an app to digitalocean using the Ruby on Rails image. It is set up by default with a user called rails. My rails.service file looks like:



[Unit] 
Description=OneMathsExamQuestions
Requires=network.target

[Service]
Type=simple
User=rails
Group=rails
WorkingDirectory=/home/rails/one_maths_exam_questions/
ExecStart=/bin/bash -lc 'bundle exec puma'
TimeoutSec=30s
RestartSec=30s
Restart=always

[Install]
WantedBy=multi-user.target


I need to use some environment variables in my application. So I have added some lines to my /home/rails/.bashrc and /root/.bashrc files (I suspect only the first one should be necessary but neither seems to work):



export A="val1"
export B="val2"
...


Now: if I call echo $A in a terminal I get the expected output. If I go into the Rails console and do ENV["A"] I get the expected output. But my app does not seem to behave correctly (the desired behaviour is connecting to Amazon S3; the exact error is not important).



If I go into my controller and explicitly log the env vars with Rails.logger.debug ENV I just get ENV, and Rails.logger.debug ENV["A"] returns empty string (I guess nil). Similarly if I try to do ENV["RAILS_ENV"] which should definitely work, I get the same. But Rails.env returns "development", as expected.



Moreover, if I explicitly write



ENV["A"] = "val1"
ENV["B"] = "val2"
...


in my config/application.rb, the app works correctly. But this is obviously not a permanent solution, since I can't commit this to version control.



I'm not using the figaro gem, which I think a lot of places are suggesting, but I don't see why I should have to since it works just fine on my local machine.










share|improve this question






















  • Do you load the rbenv in your .bashrc?

    – AHT
    Mar 22 at 13:17











  • @AHT If I understand you correctly, I think they use rvm rather than rbenv. There is a line in .bashrc which adds $HOME/.rvm/bin to the $PATH, but I think that's it.

    – preferred_anon
    Mar 22 at 13:45











  • At one point I tried to change 'bundle exec puma' to source /home/rails/.bashrc && bundle exec puma, but that seems to not work.

    – preferred_anon
    Mar 22 at 13:55











  • Exactly, you add the path and then you might need to reinitialise using source "$HOME/.rvm/scripts/rvm" if I am not mistaken.

    – AHT
    Mar 22 at 13:55











  • I don't think puma will work if you don't have the ruby environment initiated in the first place.

    – AHT
    Mar 22 at 13:58

















0















I have deployed an app to digitalocean using the Ruby on Rails image. It is set up by default with a user called rails. My rails.service file looks like:



[Unit] 
Description=OneMathsExamQuestions
Requires=network.target

[Service]
Type=simple
User=rails
Group=rails
WorkingDirectory=/home/rails/one_maths_exam_questions/
ExecStart=/bin/bash -lc 'bundle exec puma'
TimeoutSec=30s
RestartSec=30s
Restart=always

[Install]
WantedBy=multi-user.target


I need to use some environment variables in my application. So I have added some lines to my /home/rails/.bashrc and /root/.bashrc files (I suspect only the first one should be necessary but neither seems to work):



export A="val1"
export B="val2"
...


Now: if I call echo $A in a terminal I get the expected output. If I go into the Rails console and do ENV["A"] I get the expected output. But my app does not seem to behave correctly (the desired behaviour is connecting to Amazon S3; the exact error is not important).



If I go into my controller and explicitly log the env vars with Rails.logger.debug ENV I just get ENV, and Rails.logger.debug ENV["A"] returns empty string (I guess nil). Similarly if I try to do ENV["RAILS_ENV"] which should definitely work, I get the same. But Rails.env returns "development", as expected.



Moreover, if I explicitly write



ENV["A"] = "val1"
ENV["B"] = "val2"
...


in my config/application.rb, the app works correctly. But this is obviously not a permanent solution, since I can't commit this to version control.



I'm not using the figaro gem, which I think a lot of places are suggesting, but I don't see why I should have to since it works just fine on my local machine.










share|improve this question






















  • Do you load the rbenv in your .bashrc?

    – AHT
    Mar 22 at 13:17











  • @AHT If I understand you correctly, I think they use rvm rather than rbenv. There is a line in .bashrc which adds $HOME/.rvm/bin to the $PATH, but I think that's it.

    – preferred_anon
    Mar 22 at 13:45











  • At one point I tried to change 'bundle exec puma' to source /home/rails/.bashrc && bundle exec puma, but that seems to not work.

    – preferred_anon
    Mar 22 at 13:55











  • Exactly, you add the path and then you might need to reinitialise using source "$HOME/.rvm/scripts/rvm" if I am not mistaken.

    – AHT
    Mar 22 at 13:55











  • I don't think puma will work if you don't have the ruby environment initiated in the first place.

    – AHT
    Mar 22 at 13:58













0












0








0








I have deployed an app to digitalocean using the Ruby on Rails image. It is set up by default with a user called rails. My rails.service file looks like:



[Unit] 
Description=OneMathsExamQuestions
Requires=network.target

[Service]
Type=simple
User=rails
Group=rails
WorkingDirectory=/home/rails/one_maths_exam_questions/
ExecStart=/bin/bash -lc 'bundle exec puma'
TimeoutSec=30s
RestartSec=30s
Restart=always

[Install]
WantedBy=multi-user.target


I need to use some environment variables in my application. So I have added some lines to my /home/rails/.bashrc and /root/.bashrc files (I suspect only the first one should be necessary but neither seems to work):



export A="val1"
export B="val2"
...


Now: if I call echo $A in a terminal I get the expected output. If I go into the Rails console and do ENV["A"] I get the expected output. But my app does not seem to behave correctly (the desired behaviour is connecting to Amazon S3; the exact error is not important).



If I go into my controller and explicitly log the env vars with Rails.logger.debug ENV I just get ENV, and Rails.logger.debug ENV["A"] returns empty string (I guess nil). Similarly if I try to do ENV["RAILS_ENV"] which should definitely work, I get the same. But Rails.env returns "development", as expected.



Moreover, if I explicitly write



ENV["A"] = "val1"
ENV["B"] = "val2"
...


in my config/application.rb, the app works correctly. But this is obviously not a permanent solution, since I can't commit this to version control.



I'm not using the figaro gem, which I think a lot of places are suggesting, but I don't see why I should have to since it works just fine on my local machine.










share|improve this question














I have deployed an app to digitalocean using the Ruby on Rails image. It is set up by default with a user called rails. My rails.service file looks like:



[Unit] 
Description=OneMathsExamQuestions
Requires=network.target

[Service]
Type=simple
User=rails
Group=rails
WorkingDirectory=/home/rails/one_maths_exam_questions/
ExecStart=/bin/bash -lc 'bundle exec puma'
TimeoutSec=30s
RestartSec=30s
Restart=always

[Install]
WantedBy=multi-user.target


I need to use some environment variables in my application. So I have added some lines to my /home/rails/.bashrc and /root/.bashrc files (I suspect only the first one should be necessary but neither seems to work):



export A="val1"
export B="val2"
...


Now: if I call echo $A in a terminal I get the expected output. If I go into the Rails console and do ENV["A"] I get the expected output. But my app does not seem to behave correctly (the desired behaviour is connecting to Amazon S3; the exact error is not important).



If I go into my controller and explicitly log the env vars with Rails.logger.debug ENV I just get ENV, and Rails.logger.debug ENV["A"] returns empty string (I guess nil). Similarly if I try to do ENV["RAILS_ENV"] which should definitely work, I get the same. But Rails.env returns "development", as expected.



Moreover, if I explicitly write



ENV["A"] = "val1"
ENV["B"] = "val2"
...


in my config/application.rb, the app works correctly. But this is obviously not a permanent solution, since I can't commit this to version control.



I'm not using the figaro gem, which I think a lot of places are suggesting, but I don't see why I should have to since it works just fine on my local machine.







ruby-on-rails amazon-s3 deployment environment-variables digital-ocean






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 12:43









preferred_anonpreferred_anon

27217




27217












  • Do you load the rbenv in your .bashrc?

    – AHT
    Mar 22 at 13:17











  • @AHT If I understand you correctly, I think they use rvm rather than rbenv. There is a line in .bashrc which adds $HOME/.rvm/bin to the $PATH, but I think that's it.

    – preferred_anon
    Mar 22 at 13:45











  • At one point I tried to change 'bundle exec puma' to source /home/rails/.bashrc && bundle exec puma, but that seems to not work.

    – preferred_anon
    Mar 22 at 13:55











  • Exactly, you add the path and then you might need to reinitialise using source "$HOME/.rvm/scripts/rvm" if I am not mistaken.

    – AHT
    Mar 22 at 13:55











  • I don't think puma will work if you don't have the ruby environment initiated in the first place.

    – AHT
    Mar 22 at 13:58

















  • Do you load the rbenv in your .bashrc?

    – AHT
    Mar 22 at 13:17











  • @AHT If I understand you correctly, I think they use rvm rather than rbenv. There is a line in .bashrc which adds $HOME/.rvm/bin to the $PATH, but I think that's it.

    – preferred_anon
    Mar 22 at 13:45











  • At one point I tried to change 'bundle exec puma' to source /home/rails/.bashrc && bundle exec puma, but that seems to not work.

    – preferred_anon
    Mar 22 at 13:55











  • Exactly, you add the path and then you might need to reinitialise using source "$HOME/.rvm/scripts/rvm" if I am not mistaken.

    – AHT
    Mar 22 at 13:55











  • I don't think puma will work if you don't have the ruby environment initiated in the first place.

    – AHT
    Mar 22 at 13:58
















Do you load the rbenv in your .bashrc?

– AHT
Mar 22 at 13:17





Do you load the rbenv in your .bashrc?

– AHT
Mar 22 at 13:17













@AHT If I understand you correctly, I think they use rvm rather than rbenv. There is a line in .bashrc which adds $HOME/.rvm/bin to the $PATH, but I think that's it.

– preferred_anon
Mar 22 at 13:45





@AHT If I understand you correctly, I think they use rvm rather than rbenv. There is a line in .bashrc which adds $HOME/.rvm/bin to the $PATH, but I think that's it.

– preferred_anon
Mar 22 at 13:45













At one point I tried to change 'bundle exec puma' to source /home/rails/.bashrc && bundle exec puma, but that seems to not work.

– preferred_anon
Mar 22 at 13:55





At one point I tried to change 'bundle exec puma' to source /home/rails/.bashrc && bundle exec puma, but that seems to not work.

– preferred_anon
Mar 22 at 13:55













Exactly, you add the path and then you might need to reinitialise using source "$HOME/.rvm/scripts/rvm" if I am not mistaken.

– AHT
Mar 22 at 13:55





Exactly, you add the path and then you might need to reinitialise using source "$HOME/.rvm/scripts/rvm" if I am not mistaken.

– AHT
Mar 22 at 13:55













I don't think puma will work if you don't have the ruby environment initiated in the first place.

– AHT
Mar 22 at 13:58





I don't think puma will work if you don't have the ruby environment initiated in the first place.

– AHT
Mar 22 at 13:58












1 Answer
1






active

oldest

votes


















0














OK, it looks like if I export my environment variables in .profile then they are picked up by the server no problem. If I remove them from .bashrc then the server has no problems, but I can't get the variables in terminal. I guess they just do different things?






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    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%2fstackoverflow.com%2fquestions%2f55299893%2fdeployed-digitalocean-app-isnt-reading-environment-variables%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














    OK, it looks like if I export my environment variables in .profile then they are picked up by the server no problem. If I remove them from .bashrc then the server has no problems, but I can't get the variables in terminal. I guess they just do different things?






    share|improve this answer



























      0














      OK, it looks like if I export my environment variables in .profile then they are picked up by the server no problem. If I remove them from .bashrc then the server has no problems, but I can't get the variables in terminal. I guess they just do different things?






      share|improve this answer

























        0












        0








        0







        OK, it looks like if I export my environment variables in .profile then they are picked up by the server no problem. If I remove them from .bashrc then the server has no problems, but I can't get the variables in terminal. I guess they just do different things?






        share|improve this answer













        OK, it looks like if I export my environment variables in .profile then they are picked up by the server no problem. If I remove them from .bashrc then the server has no problems, but I can't get the variables in terminal. I guess they just do different things?







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 16:10









        preferred_anonpreferred_anon

        27217




        27217





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • 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%2fstackoverflow.com%2fquestions%2f55299893%2fdeployed-digitalocean-app-isnt-reading-environment-variables%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript