Class: FPM::Fry::Plugin::Service::DSL
- Inherits:
-
Object
- Object
- FPM::Fry::Plugin::Service::DSL
- Defined in:
- lib/fpm/fry/plugin/service.rb
Instance Attribute Summary collapse
-
#limits ⇒ Object
readonly
Returns the value of attribute limits.
Instance Method Summary collapse
- #add!(builder) ⇒ Object private
- #chdir(dir = nil) ⇒ Object
- #command(*args) ⇒ Object
- #group(n = nil) ⇒ Object
-
#initialize(*_) ⇒ DSL
constructor
A new instance of DSL.
- #limit(name, soft, hard = soft) ⇒ Object
- #name(n = nil) ⇒ Object
- #user(n = nil) ⇒ Object
Constructor Details
#initialize(*_) ⇒ DSL
Returns a new instance of DSL.
29 30 31 32 33 34 35 36 37 |
# File 'lib/fpm/fry/plugin/service.rb', line 29 def initialize(*_) super @name = nil @command = [] @limits = {} @user = nil @group = nil @chdir = nil end |
Instance Attribute Details
#limits ⇒ Object (readonly)
Returns the value of attribute limits.
27 28 29 |
# File 'lib/fpm/fry/plugin/service.rb', line 27 def limits @limits end |
Instance Method Details
#add!(builder) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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 |
# File 'lib/fpm/fry/plugin/service.rb', line 82 def add!(builder) name = self.name || builder.name || raise init = Init.detect_init(builder.variables) edit = builder.plugin('edit_staging') env = Environment.new(name, command, "", @limits, @user, @group, @chdir) case(init) when 'upstart' then edit.add_file "/etc/init/#{name}.conf",StringIO.new( env.render('upstart.erb') ) edit.ln_s '/lib/init/upstart-job', "/etc/init.d/#{name}" builder.plugin('script_helper') do |sh| sh.after_install_or_upgrade(<<BASH) if status #{Shellwords.shellescape name} 2>/dev/null | grep -q ' start/'; then # It has to be stop+start because upstart doesn't pickup changes with restart. if which invoke-rc.d >/dev/null 2>&1; then invoke-rc.d #{Shellwords.shellescape name} stop else stop #{Shellwords.shellescape name} fi fi if which invoke-rc.d >/dev/null 2>&1; then invoke-rc.d #{Shellwords.shellescape name} start else start #{Shellwords.shellescape name} fi BASH sh.before_remove_entirely(<<BASH) if status #{Shellwords.shellescape name} 2>/dev/null | grep -q ' start/'; then stop #{Shellwords.shellescape name} fi BASH end builder.plugin('config', FPM::Fry::Plugin::Config::IMPLICIT => true) do |co| co.include "etc/init/#{name}.conf" end when 'sysv' then edit.add_file "/etc/init.d/#{name}",StringIO.new( env.render('sysv.erb') ), chmod: '750' builder.plugin('script_helper') do |sh| sh.after_install_or_upgrade(<<BASH) update-rc.d #{Shellwords.shellescape name} defaults /etc/init.d/#{Shellwords.shellescape name} restart BASH sh.before_remove_entirely(<<BASH) /etc/init.d/#{Shellwords.shellescape name} stop update-rc.d -f #{Shellwords.shellescape name} remove BASH end builder.plugin('config', FPM::Fry::Plugin::Config::IMPLICIT => true) do |co| co.include "etc/init.d/#{name}" end when 'systemd' then end end |
#chdir(dir = nil) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/fpm/fry/plugin/service.rb', line 67 def chdir( dir = nil ) if dir @chdir = dir end @chdir end |
#command(*args) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/fpm/fry/plugin/service.rb', line 74 def command( *args ) if args.any? @command = args end return @command end |
#group(n = nil) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/fpm/fry/plugin/service.rb', line 46 def group( n = nil ) if n @group = n end return @group end |
#limit(name, soft, hard = soft) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/fpm/fry/plugin/service.rb', line 60 def limit( name, soft, hard = soft ) unless LIMITS.include? name raise ArgumentError, "Unknown limit #{name.inspect}. Known limits are: #{LIMITS.inspect}" end @limits[name] = [soft,hard] end |
#name(n = nil) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/fpm/fry/plugin/service.rb', line 39 def name( n = nil ) if n @name = n end return @name end |
#user(n = nil) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/fpm/fry/plugin/service.rb', line 53 def user( n = nil ) if n @user = n end return @user end |