How do I fix “Error: MONGO_URL must be set in environment” on ubuntu using forever and startup script?

夙愿已清 提交于 2019-12-06 05:10:31

问题


I just deployed a meteor js app on an EC2 ubuntu server. I installed forever and added the following startup script to /etc/init/meteor.conf

start on (local-filesystems)
stop on shutdown

script
        cd /home/ubuntu
        export PORT=80 MONGO_URL=mongodb://localhost27017/parties ROOT_URL=http://ec2-54-235-1-185.compute-1.amazonaws.com
        exec forever start bundle/main.js

end script

When I go to start my app using: sudo service meteor start, it reads:

meteor start/running, process 12481
ubuntu@ip-10-98-57-161:~$ 

But when I enter the public DNS in my browser, nothing.

So I then type the command forever list and it list three rows with some information and a column for log files. So I then open the last log file in vim to see it's contents and I'm seeing the following error:

/home/ubuntu/bundle/programs/server/boot.js:184
}).run();
   ^
Error: MONGO_URL must be set in environment
    at Object.<anonymous> (packages/mongo-livedata/remote_collection_driver.js:32)
    at Object._.once [as defaultRemoteCollectionDriver] (packages/underscore/underscore.js:704)
    at new Meteor.Collection (packages/mongo-livedata/collection.js:66)
    at packages/service-configuration/service_configuration_common.js:8
    at packages/service-configuration.js:43:4
    at packages/service-configuration.js:52:3
    at mains (/home/ubuntu/bundle/programs/server/boot.js:153:10)
    at Array.forEach (native)
    at Function._.each._.forEach (/home/ubuntu/bundle/programs/server/node_modules/underscore/underscore.js:79:11)
    at /home/ubuntu/bundle/programs/server/boot.js:80:5
error: Forever detected script exited with code: 1

I've tried about ten different ways of starting the app and everytime I get the same error. One thing worth mentioning: When I run my app using:

sudo PORT=80 MONGO_URL=mongodb://localhost:27017/parties ROOT_URL=http://ec2-54-235-1-185.compute-1.amazonaws.com node bundle/main.js

It starts up, and I can access it through my public DNS, but of course, as soon as I close my terminal the app dies.

Does anybody know how I can fix this?


回答1:


it looks to me as if you forgot the colon ´:´ in your mongourl

export PORT=80 MONGO_URL=mongodb://localhost:27017/parties ROOT_URL=http://ec2-54-235-1-185.compute-1.amazonaws.com

have you tried that?




回答2:


Try passing it onto forever straight without using the export before:

exec PORT=80 MONGO_URL=mongodb://localhost27017/parties ROOT_URL=http://ec2-54-235-1-185.compute-1.amazonaws.com forever start bundle/main.js

It might have something to do with the permissions, when using a startup script the user might be something that has its own variable scope to the ones set.



来源:https://stackoverflow.com/questions/18359326/how-do-i-fix-error-mongo-url-must-be-set-in-environment-on-ubuntu-using-forev

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!