Ubuntu 16.04: set systemd for meteor service


Hi, i’m have a vps with ubuntu 16.04 and i following this guide for install nginx + meteor.


The problem is that guide is for ubuntu 14.04 and use startup. In ubuntu 16.04 there is systemd.
How can i translate this startup’s code in sistemd?

upstart service file at /etc/init/todos.conf

description "Meteor.js (NodeJS) application"
author “Daniel Speichert daniel@speichert.pro

When to start the service

start on started mongodb and runlevel [2345]

When to stop the service

stop on shutdown

Automatically restart process if crashed

respawn limit 10 5

we don’t use buil-in log because we use a script below

console log

drop root proviliges and switch to mymetorapp user

setuid todos
setgid todos

export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
# set to home directory of the user Meteor will be running as
export PWD=/home/todos
export HOME=/home/todos
# leave as for security
export BIND_IP=
# the port nginx is proxying requests to
export PORT=8080
# this allows Meteor to figure out correct IP address of visitors
# MongoDB connection string using todos as database name
export MONGO_URL=mongodb://localhost:27017/todos
# The domain name as configured previously as server_name in nginx
export ROOT_URL=https://todos.net
# optional JSON config - the contents of file specified by passing “–settings” parameter to meteor command in development mode
export METEOR_SETTINGS=’{ “somesetting”: “someval”, “public”: { “othersetting”: “anothervalue” } }’
# this is optional: http://docs.meteor.com/#email
# commented out will default to no email being sent
# you must register with MailGun to have a username and password there
# export MAIL_URL=smtp://postmaster@mymetorapp.net:password123@smtp.mailgun.org
# alternatively install “apt-get install default-mta” and uncomment:
# export MAIL_URL=smtp://localhost
exec node /home/todos/bundle/main.js >> /home/todos/todos.log
end script


maybe this will help:


The problem I have with that outline is that it is unrealistic to expect JSON to be hardcoded in METEOR_SETTINGS.

Previously I had used JSAWK to read in settings files, but that is no longer possible, and running an ExecStartPre script doesn’t allow for setting the env vars for the correct process,

Any other great ideas?


As an afterthought was thinking that I could execute a script to setup an EnvironmentFile which can them be imported in the systemd unit file. Trying that option myself now, and it seems to work a charm.


I am attempting to do the same thing, after migrating some Meteor apps on Ubuntu 14.04 to Meteor on Ubuntu 18.04.
Does anyone have a systemd equivalent working for the init file in the original question?


This is mine /etc/systemd/system/SERVICE-NAME.service file:

ExecStart=/usr/bin/node /PATH/TO/THE/bundle/main.js
Environment='METEOR_SETTINGS={"someSetting": "someValue"}'

1 Like

Thanks. I spent time experimenting and this is very close to what I ended up with as well.
for Restart I chose on-failure, and i’ll look at adding NODE_ENV as you have,