Top Level Namespace
Defined Under Namespace
Classes: RunitServiceBuilder
Instance Method Summary collapse
-
#runit_service(name, &block) ⇒ Object
Defines a runit service.
Instance Method Details
#runit_service(name, &block) ⇒ Object
Defines a runit service.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/cap-runit.rb', line 75 def runit_service(name, &block) runit_service_dir = fetch(:runit_service_dir) service = RunitServiceBuilder.new(&block) namespace name do desc "Configure #{name} runit" task :configure do on roles(service.roles), in: :groups, limit: 4 do unless test("[ -e #{runit_service_dir}/#{name}/run ]") execute <<-EOF rm -rf #{runit_service_dir}/#{name} mkdir -p #{runit_service_dir}/#{name}/log EOF upload! StringIO.new(service.run), "#{runit_service_dir}/#{name}/run" if service.log upload! StringIO.new(service.log), "#{runit_service_dir}/#{name}/log/run" end if service.finish upload! StringIO.new(service.finish), "#{runit_service_dir}/#{name}/finish" end execute "chmod +x #{runit_service_dir}/#{name}/run #{runit_service_dir}/#{name}/log/run" end end end desc "Start #{name}" task start: :configure do on roles(*service.roles), in: :groups, limit: 4 do execute "sv start #{runit_service_dir}/#{name}" end end desc "Stop #{name}" task :stop do on roles(*service.roles), in: :groups, limit: 4 do execute "sv stop #{runit_service_dir}/#{name}" end end desc "Force stop #{name}" task :force_stop do on roles(*service.roles), in: :groups, limit: 4 do execute "sv force-stop #{runit_service_dir}/#{name} || true" end end task :'force-stop' => :force_stop desc "Restart #{name}" task restart: :configure do on roles(*service.roles), in: :groups, limit: 4 do execute "sv restart #{runit_service_dir}/#{name}" end end desc "Force restart #{name}" task force_restart: :configure do on roles(*service.roles), in: :groups, limit: 4 do execute "sv force-restart #{runit_service_dir}/#{name} || true" end end task :'force-restart' => :force_restart desc "Disable #{name}" task :disable do on roles(*service.roles), in: :groups, limit: 4 do execute "rm -rf #{runit_service_dir}/#{name}" end end end end |