Sunday 19 March 2017

Systemd service for Node server can't connect to MongoDB

I have created a Systemd unit file to run Mongodb on system startup. I have also created a systemd service to run my node application on startup after mongodb is started. The service for mongodb works fine, but for some reason my service for the Node application tries to run and then gives the error: "MongoError: failed to connect to server [localhost:27017] on first connect". If I start the mongodb service using $systemctl start mongodb and then start my Node application using $/usr/bin/node /node_app_slot/server.js It seems to work fine. So the problem seems to be with my systemd unit file for my Node server.

I used this for the mongodb systemd service https://gist.github.com/jwilm/5842956

And here is my node_server.service:

[Unit]
Wants=network.target mongodb.service
After=network.target mongodb.service

[Service]
ExecStart=/usr/bin/node /node_app_slot/server.js

[Install]
WantedBy=multi-user.target

Im doing this on an intel edison set up in Access Point mode using hostapd. The OS is Yocto and is up to date with the latest release.

I can't see where Im going wrong. I will really appreciate it if someone could guide me in the right direction!

Thanks!



via Myatt95

No comments:

Post a Comment