-
Notifications
You must be signed in to change notification settings - Fork 108
Environment vars not accessible by service #84
Comments
Ruby syntax oops, remove the space between |
O.o! Now works (sometimes I forgot that it's Ruby, haha). And it needs to be just at beginning of Thank you @coderanger ! |
Ordering shouldn't matter in theory, though I would have to step through the code to see if I screwed up a copy or something. |
Yes, strange @coderanger . Here is my full recipe, with this config (environment in the middle) it do not pass my env var to systemd conf, but if it is just after start application block it works. node['python-app'].each do |app|
application '/srv/' + app['name'] do
git do
repository app['repo']
revision app['branch'] if app['branch']
deploy_key data_bag_item('ssh_keys', app['deploy_key'])['key'] if app['deploy_key']
end
virtualenv
pip_requirements
# Setup environment file
env_filename = "/srv/#{app['name']}/env.prod.py"
# Just to not break deploy
file env_filename do
content ''
mode '0777'
action :create_if_missing
end
execute 'create env modue' do
command "cp #{env_filename} /srv/#{app['name']}/env.py"
end
# We need this to do a warm shutdown with Celery, with this it's possible to
# use auto scalling and other features that needs to send a SIGTERM to celery worker
# and not lose current tasks in process.
#
# For more information about this ENV VAR: https://github.com/celery/celery/issues/2839
#
# With this env var it's good to use a DefaultTimeoutStopSec as infinity at default config or a
# TimeoutStopSec with same value at your service.
environment REMAP_SIGTERM: 'SIGQUIT'
# SystemD default conf
template '/etc/systemd/system.conf' do
source 'systemdconf.erb'
mode '0644'
owner 'root'
group 'root'
end
# Setup celery
if app.fetch('celery', true)
celery_config do
options do
celeryd_concurrency app.fetch('concurrency', 1)
celery_default_queue app.fetch('queue_name', 'celery') if app.key? 'queue_name'
# http://docs.celeryproject.org/en/latest/userguide/configuration.html#worker-prefetch-multiplier
celeryd_prefetch_multiplier 1
end
end
file "/srv/#{app['name']}/celeryconfig.py" do
mode '0777'
end
celery_worker do
app_module 'tasks'
user 'celery'
service_name "s#{app['name']}"
end
end
end
end |
Aha, yep, order does matter because I So if something tries to use the app state before you set the environment, it would be too late. I should figure out a better way to handle that. |
hum, understood @coderanger ! I'm using a lot of this recipes, If I figure out a good way to improve this I'll comment on issue or contribute by other way. |
Specifically in this case you need to set the property before using the virtualenv resource because that does a compile time change to the app state. |
Hi guys!
I'm trying to fill systemd
Environment
variables fromcelery_worker
. I saw it has ServiceMixin frompoise-service
interface but unfortunately I can't find a way to pass my env vars to service environment.I'm trying to do like this:
But my
Environment
entry onsystemd
service conf still empty.Am I doing something wrong?
Thanks in advance!
Alisson
The text was updated successfully, but these errors were encountered: