Class: Initd::Script

Inherits:
Object
  • Object
show all
Defined in:
lib/initd/script.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, script, args, user) ⇒ Script

Returns a new instance of Script.



9
10
11
12
13
14
15
16
17
18
# File 'lib/initd/script.rb', line 9

def initialize(path, script, args, user)
  @path = path
  @daemon = {
      :name => name,
      :script => script,
      :args => args,
      :user => user,
  }
  @description = name
end

Instance Attribute Details

#daemonObject (readonly)

Returns the value of attribute daemon.



3
4
5
# File 'lib/initd/script.rb', line 3

def daemon
  @daemon
end

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/initd/script.rb', line 3

def description
  @description
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/initd/script.rb', line 3

def path
  @path
end

Instance Method Details

#contentObject



28
29
30
31
# File 'lib/initd/script.rb', line 28

def content
  template = templates_dir.join('script.erb')
  ERB.new(template.read, nil, '<>').result(binding)
end

#nameObject



20
21
22
# File 'lib/initd/script.rb', line 20

def name
  @path.basename.to_s
end

#pidfileObject



24
25
26
# File 'lib/initd/script.rb', line 24

def pidfile
  Pathname.new('/var/run').join(@daemon[:name]).join("#{@daemon[:name]}.pid")
end

#templates_dirObject



5
6
7
# File 'lib/initd/script.rb', line 5

def templates_dir
  Pathname.new(__FILE__).dirname.dirname.dirname.join('templates')
end