groovenauts / capistrano-systemd-multiservice

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

Setup all registered services #27

Closed prem-prakash closed 3 years ago

prem-prakash commented 3 years ago

Is there an easy way to set up all registered services with a single command?

minimum2scp commented 3 years ago

No, but you can define your custom task like this:

task :setup_all_services do
  invoke 'systemd:example1:setup'
  invoke 'systemd:example2:setup'
end
prem-prakash commented 3 years ago

I am intending to automate in a way that all services that were registered could be set up at once, without having to list each one of the services. But unfortunately, I am no expert in capistrano, so I don't know how to do that.

minimum2scp commented 3 years ago

without having to list each one of the services

Hmm, I prefer to write all service names explicitly, but you meen you don't want to write service names explicitly, like this?

task :setup_all_services do
  some_method_returns_all_registered_services.each do |service_name|
    invoke "systemd:#{service_name}:setup"
  end
end

If you really want to do that, ObjectSpace.each_object returns registered services.

task :setup_all_services do
  ObjectSpace.each_object(Capistrano::Systemd::MultiService::SystemService).map(&:app).each do |service_name|
    invoke "systemd:#{service_name}:setup"
  end
end
prem-prakash commented 3 years ago

Yeah that's exactly what I needed. Thank you very much.