groovenauts / capistrano-systemd-multiservice

Capistrano Plugin to control services with systemd
MIT License
45 stars 17 forks source link

support access to `server` in .service template #11

Closed takumiabe closed 5 years ago

takumiabe commented 5 years ago

this change can do like this:

config/deploy/xxxx.rb

server "1.2.3.4", roles: %w{app web db}, puma_port: 8080

config/systemd/puma.service.erb

...

[Service]
...
ExecStart=bundle exec puma -C <%= current_path %>/config/puma.rb -p <%= server.properties.puma_port %>

...

I update a lot of rspecs, but I'm not sure it is right... :(

minimum2scp commented 5 years ago

Why don't you put port number configuration to config/puma.rb?

takumiabe commented 5 years ago

@minimum2scp Thank you for comment!

sorry, It is (my personal) too complex case, :( I have many sub-app on a single service under loadbalancer. (I call them A, B ,C here)

then, I want to setup this case:

I think it is difficult to implement this case by only config/puma.rb (neither ENV inside puma.rb)

thanks

minimum2scp commented 5 years ago

@takumiabe Thanks, I understand.

I found that I can access server properties by backend.host.properties (an instance of Capistrano::Configuration::Server::Properties), so maybe you can set port number by backend.host.properties.fetch(:puma_port) in config/systemd/puma.service.erb.

...

[Service]
...
ExecStart=bundle exec puma -C <%= current_path %>/config/puma.rb -p <%= backend.host.properties.fetch(:puma_port) %>

...

Please try.

takumiabe commented 5 years ago

@minimum2scp Ohh, It works! (Sorry, I searched by "server", but by "host")

Thank you for better solution!