-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathservice
33 lines (33 loc) · 1007 Bytes
/
service
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
local args = {...}
if #args == 2 and args[1] == "start" then
local path = shell.resolveProgram(args[2])
if path then
process.new(function() shell.run(path) end, fs.getName(path))
end
elseif #args == 2 and args[1] == "stop" or args[1] == "restart" then
local proc = process.getFromName(args[2])
if proc then
proc:resume({"service_stop"})
proc:kill()
end
--also include restart here, to take advantage of stop code.
if args[1] == "restart" then
local path = shell.resolveProgram(args[2])
if path then
process.new(function() shell.run(path) end, fs.getName(path))
end
end
elseif #args == 1 and args[1] == "console" then
while true do
local event = {os.pullEvent()}
if event[1] == "service_message" then
print(event[3].."-"..event[2]..": "..event[4])
end
end
else
print("Usage:")
print(fs.getName(shell.getRunningProgram()).." start <path>")
print(fs.getName(shell.getRunningProgram()).." stop <path>")
print(fs.getName(shell.getRunningProgram()).." console")
return
end