3

I have a simple Meteor web app that I am trying to host on my own server. Server details;

  • Debian (Jessie) Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt2-1 (2014-12-08) x86_64 GNU/Linux
  • systemd
  • NodeJS version 0.10.36
  • Meteor version 1.0.3.1
  • MongoDB version 2.6.7

/etc/systemd/system/customwebapp.service file;

[Service]
ExecStart=/usr/bin/node /opt/customwebapp/bundle/main.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=customwebapp
User=customwebapp
Group=customwebapp
Environment=NODE_ENV=production MONGO_URL='mongodb://localhost'

[Install]
WantedBy=multi-user.target

I create the service account using;

sudo useradd -mrU customwebapp

I build the Meteor app using;

sudo meteor build --directory /opt/customwebapp
cd /opt/customwebapp/programs/server
sudo npm install

I try to register the service with;

sudo systemctl enable customwebapp
sudo systemctl start customwebapp

Syslog reports the following;

/opt/customwebapp/bundle/programs/server/node_modules/fibers/future.js:173
Error: URL must be in the format mongodb://user:pass@host:port/dbname
at Error (<anonymous>)

I have tried for hours to fix this problem. I have used a number of different MONGO_URL values. I created an admin or root user in MongoDB using the mongo command and put the user:pass@localhost:27017/customwebapp format into the URL environment variable.

No matter what I do it comes back with the same error.

I have also tried using Meteor Up but it seems to configure Upstart not systemd.

And it goes without saying, I have tried a large number of solutions from SO. Not all of the solutions I have tried are listed here.

I suspect the reason I am having issues is because of systemd.

This is my first question on SO because, to be honest, most problems I have somebody else has had the issue before me. SO is brilliant for helping me and has many times. Now I'm hoping SO will help again.

Thanks for taking the time to help.

Grant Carthew
  • 177
  • 1
  • 10

1 Answers1

6

OK, I found the issue after digging into source code in the NodeJS core module called Url

As you can see from my question above I was setting the Environment in the service unit file using this line;

Environment=NODE_ENV=production MONGO_URL='mongodb://localhost'

The Node Url module was detecting the single quotes ' and replacing them with %27. This caused the Url.parse function to fail setting the host value.

Here is the correct way to set the Environment values on multiple lines and without the single quotes;

Environment=NODE_ENV=production
Environment=MONGO_URL=mongodb://localhost
Environment=ROOT_URL=http://localhost:8080
Environment=PORT=8080

It's always the little syntax issues isn't it.

Grant Carthew
  • 177
  • 1
  • 10