Class: Simultaneous::Command::Fire
Instance Attribute Summary collapse
Attributes inherited from CommandBase
#params, #tag, #task
Instance Method Summary
collapse
Methods inherited from CommandBase
#domain, #domain=, #dump, #merge_params, #namespaced_task_name, #task_name
Constructor Details
#initialize(task, params = {}) ⇒ Fire
Returns a new instance of Fire.
10
11
12
13
14
|
# File 'lib/simultaneous/command/fire.rb', line 10
def initialize(task, params={})
super
@task_uid = Process.euid
@task_gid = Process.egid
end
|
Instance Attribute Details
#task_gid ⇒ Object
Returns the value of attribute task_gid.
8
9
10
|
# File 'lib/simultaneous/command/fire.rb', line 8
def task_gid
@task_gid
end
|
#task_uid ⇒ Object
Returns the value of attribute task_uid.
8
9
10
|
# File 'lib/simultaneous/command/fire.rb', line 8
def task_uid
@task_uid
end
|
Instance Method Details
#binary ⇒ Object
20
21
22
|
# File 'lib/simultaneous/command/fire.rb', line 20
def binary
@task.binary
end
|
#binary_file ⇒ Object
24
25
26
|
# File 'lib/simultaneous/command/fire.rb', line 24
def binary_file
@task.binary.split(" ").first
end
|
#cmd ⇒ Object
28
29
30
|
# File 'lib/simultaneous/command/fire.rb', line 28
def cmd
%(#{binary} #{Simultaneous.to_arguments(@params)})
end
|
#debug ⇒ Object
77
78
79
|
# File 'lib/simultaneous/command/fire.rb', line 77
def debug
"Fire :#{namespaced_task_name}: #{cmd}\n"
end
|
#exists? ⇒ Boolean
41
42
43
44
|
# File 'lib/simultaneous/command/fire.rb', line 41
def exists?
raise FileNotFoundError, "'#{binary_file}'" unless File.exists?(binary_file)
true
end
|
#niceness ⇒ Object
16
17
18
|
# File 'lib/simultaneous/command/fire.rb', line 16
def niceness
@task.niceness
end
|
#permitted? ⇒ Boolean
36
37
38
39
|
# File 'lib/simultaneous/command/fire.rb', line 36
def permitted?
raise PermissionsError, "'#{binary_file}' does not belong to user '#{ENV["USER"]}'" unless File.stat(binary_file).uid == task_uid
true
end
|
#run ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/simultaneous/command/fire.rb', line 54
def run
if valid?
pid = fork do
env.each { | k, v | ENV[k] = v }
daemonize(cmd, @task.logfile)
Process.setpriority(Process::PRIO_PROCESS, 0, niceness) if niceness > 0
Process::GID.change_privilege(task_gid) unless Process.egid == task_gid
Process::UID.change_privilege(task_uid) unless Process.euid == task_uid
File.umask(0022)
redirect_io(@task.logfile)
Dir.chdir(@task.pwd)
exec(cmd)
end
Process.detach(pid) if pid
"OK"
end
end
|
#valid? ⇒ Boolean
32
33
34
|
# File 'lib/simultaneous/command/fire.rb', line 32
def valid?
exists? && permitted?
end
|