forked from abduct/Brainlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestart.rb
executable file
·44 lines (35 loc) · 1.27 KB
/
restart.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Brainlet
module Service
module_function
def restart(config)
cmd = config[:cmd]
prompt = config[:prompt]
name = ""
printer_profiles = []
Dir.chdir("/home/#{ENV['SUDO_USER']}/configs") do
printer_profiles = Dir.glob("*").select { |f| File.directory? f }
end
loop do
name = prompt.select("Which printer would you like to restart?", printer_profiles)
break if prompt.yes?("Are you sure you would like to restart #{name}?")
end
cmd.run "systemctl restart #{name}-klipper.service"
cmd.run "systemctl restart #{name}-moonraker.service"
cmd.run! "systemctl restart #{name}-webcam.service"
end
def restart_all(config)
cmd = config[:cmd]
prompt = config[:prompt]
return if prompt.yes?("Are you sure you would like to restart all services?")
printer_profiles = []
Dir.chdir("/home/#{ENV['SUDO_USER']}/configs") do
printer_profiles = Dir.glob("*").select { |f| File.directory? f }
end
printer_profiles.each do |name|
cmd.run "systemctl restart #{name}-klipper.service"
cmd.run "systemctl restart #{name}-moonraker.service"
cmd.run! "systemctl restart #{name}-webcam.service"
end
end
end
end