Joost Döbken
Joost Döbken

Reputation: 4017

Supervisor using Meteor settings.json On Launch

How to pass a --settings json file to meteor with supervisor? If I run the meteor run command from the home command, everything is perfect:

meteor --settings settings.json

This is my current conf.d file:

[program:demo]
command=/usr/local/bin/meteor
directory=/home/username/demo
autostart=true
autorestart=true
environment=
    HOME="/home/username",
    METEOR_SETTINGS="/home/username/demo/settings.json"
stdout_logfile=/home/username/demo.log
stdout_logfiel_maxbytes=50MB
user=username

which gives the following error:

Errors prevented isopacket load:

While loading isopacket `constraint-solver`:
packages/meteor.js:59:11: METEOR_SETTINGS are not valid JSON:
/home/username/demo/settings.json
at packages/meteor.js:59:11
at packages/meteor.js:80:4
at packages/meteor.js:1380:3

settings.json

{
  "private": {
    "init_admin": {
      "userName": "admin",
      "email": "[email protected]",
      "password": "test123"
    }
  }
}

Upvotes: 0

Views: 473

Answers (1)

Stefan Midjich
Stefan Midjich

Reputation: 510

I'm surprised no one has answered this already. I found your question on google when trying to figure out how to put the settings.json file into METEOR_SETTINGS and avoid syntax errors in the supervisor config.

Because to answer your question, METEOR_SETTINGS environment variable must contain JSON. So it must contain the JSON data of settings.json, not the filename or path.

Which is kinda dumb because you're putting JSON data into an environment variable. So basically METEOR_SETTINGS="$(cat settings.json|tr -d '\n')" but doing this causes problems with supervisord since this syntax apparently is not supported.

"error: <class 'xmlrpclib.Fault'>, <Fault 92: 'CANT_REREAD: Unexpected end of key/value pairs'>: file: /usr/lib64/python2.7/xmlrpclib.py line: 794"]

My permanent solution was to wrap the node command with a shell script so that I could properly set the METEOR_SETTINGS variable in bash instead of supervisord.

So remove METEOR_SETTINGS from your environment in supervisord. (Here is an example from my Ansible so that's why values are enclosed by brackets)

[program:pwfrank]                                                                                                                            
directory={{pwfrank_home}}/build/bundle                                                                                                      
command={{pwfrank_home}}/start_node.sh 
environment=                                                                                                                                 
  HOME="{{pwfrank_home}}",                                                                                                                   
  MONGO_URL="{{pwfrank_mongo_url}}",                                                                                                         
  PORT="{{pwfrank_listenport}}",                                                                                                             
  ROOT_URL="{{pwfrank_baseurl}}"                                                                                                             

And create a shell script like this for example.

#!/usr/bin/env bash

export METEOR_SETTINGS="$(cat {{pwfrank_home}}/pwfrank/{{pwfrank_settings_file}} | tr -d '\n')"                                              

/usr/local/bin/meteor node main.js    

This worked for me but I'm moving away from supervisor and into systemd instead because systemd has environment files so I won't have to use shell scripts to wrap node.

Edit for future googlers: I ended up realizing that systemd works fine as long as you put the json data beteween single quote marks. Personally I accomplish this with ansible, extracting the JSON data with the cat|tr command I mentioned above, putting it into an ansible fact and then using the fact in the template of my EnvironmentFile for the Meteor service unit in systemd.

Upvotes: 1

Related Questions