rwaffen rwaffen - 5 months ago 23
Ruby Question

sinatra will not load config data when started via systemd

i have a sinatra app. when loaded locally via bundler, everything is fine. when i load the app via systemd the app got started, but the config file seems to be not loading. It says that in the logs that its loaded but the values are not available inside the app

The unit file:

[Unit]
Description=PNL: Puppet Node Lister
After=network.target

[Service]
Type=simple
ExecStart=/bin/bundle exec ruby puppetdb_node_lister.rb
KillMode=process
Environment=RACK_ENV="production"
Restart=always
User=pnl
Group=pnl
WorkingDirectory=/opt/puppetdb_node_lister

[Install]
WantedBy=multi-user.target


my sinatra app:

require 'rubygems'
require 'sinatra'
require 'sinatra/config_file'
require 'json'
require 'rest-client'
require 'date'
require 'time'
require 'active_support/time_with_zone'
require 'tilt/erb'

### local methods
require_relative 'lib/methods.rb'

config_file 'config.yaml'

### request area
get '/' do
"#{settings.methods(false).inspect} <br/><br/> #{$:} <br/><br/> #{File.expand_path(File.dirname(__FILE__))}"

end


my yaml:

development:
username: 'test'
password: 'test'
puppetdb: 'puppet.example.com'
puppetsrv: 'puppet.example.com'
production:
username: 'superadmin'
password: 'somes3cret'
puppetdb: 'puppet.example.com'
puppetsrv: 'puppet.example.com'


local bundle output of /

[:app_file=, :app_file, :app_file?, :logging=, :logging, :logging?, :method_override=, :method_override, :method_override?, :run=, :run, :run?, :session_secret=, :session_secret, :session_secret?, :register, :environments=, :environments, :environments?, :username=, :username, :username?, :password=, :password, :password?, :puppetdb=, :puppetdb, :puppetdb?, :puppetsrv=, :puppetsrv, :puppetsrv?, :traps=, :traps, :traps?, :running_server=, :running_server, :running_server?, :handler_name=, :handler_name, :handler_name?]

["/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/sinatra-contrib-1.4.7/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/sinatra-1.4.7/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/tilt-2.0.4/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/rubygems-update-2.6.4/hide_lib_for_update", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/rest-client-1.8.0/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/rack-test-0.6.3/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/rack-protection-1.5.3/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/rack-1.6.4/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/netrc-0.11.0/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/multi_json-1.12.1/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/mime-types-2.99.2/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/http-cookie-1.0.2/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/domain_name-0.5.20160310/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/unf-0.1.4/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/unf_ext-0.0.7.2/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/unf_ext-0.0.7.2/lib", "/usr/share/gems/gems/bundler-1.7.8/lib/gems/bundler-1.7.8/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/backports-3.6.8/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/activesupport-4.2.6/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/tzinfo-1.2.2/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/thread_safe-0.3.5/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/minitest-5.9.0/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/json-1.8.3/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/json-1.8.3/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/i18n-0.7.0/lib", "/usr/share/gems/gems/bundler-1.7.8/lib", "/usr/local/share/ruby/site_ruby", "/usr/local/lib64/ruby/site_ruby", "/usr/share/ruby/vendor_ruby", "/usr/lib64/ruby/vendor_ruby", "/usr/share/rubygems", "/usr/share/ruby", "/usr/lib64/ruby/"]

/opt/puppetdb_node_lister


systemd output of /

[:app_file=, :app_file, :app_file?, :logging=, :logging, :logging?, :method_override=, :method_override, :method_override?, :run=, :run, :run?, :session_secret=, :session_secret, :session_secret?, :register, :environments=, :environments, :environments?, :traps=, :traps, :traps?, :running_server=, :running_server, :running_server?, :handler_name=, :handler_name, :handler_name?]

["/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/sinatra-contrib-1.4.7/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/sinatra-1.4.7/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/tilt-2.0.4/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/rubygems-update-2.6.4/hide_lib_for_update", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/rest-client-1.8.0/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/rack-test-0.6.3/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/rack-protection-1.5.3/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/rack-1.6.4/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/netrc-0.11.0/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/multi_json-1.12.1/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/mime-types-2.99.2/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/http-cookie-1.0.2/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/domain_name-0.5.20160310/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/unf-0.1.4/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/unf_ext-0.0.7.2/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/unf_ext-0.0.7.2/lib", "/usr/share/gems/gems/bundler-1.7.8/lib/gems/bundler-1.7.8/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/backports-3.6.8/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/activesupport-4.2.6/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/tzinfo-1.2.2/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/thread_safe-0.3.5/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/minitest-5.9.0/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/json-1.8.3/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/json-1.8.3/lib", "/opt/puppetdb_node_lister/vendor/bundle/ruby/gems/i18n-0.7.0/lib", "/usr/share/gems/gems/bundler-1.7.8/lib", "/usr/local/share/ruby/site_ruby", "/usr/local/lib64/ruby/site_ruby", "/usr/share/ruby/vendor_ruby", "/usr/lib64/ruby/vendor_ruby", "/usr/share/rubygems", "/usr/share/ruby", "/usr/lib64/ruby/"]

/opt/puppetdb_node_lister


one can see, that if loaded via systemd the values in settings (which would come from the yaml) are missing.

can anybody help me with that? am i doing this right, or is there i'm missing something?

Answer

after all it was

Environment=RACK_ENV="production"

which should be more like

Environment=RACK_ENV=production

after this change, everything worked as expected!