mirror of
https://github.com/munki/munki.git
synced 2026-04-29 00:39:42 -05:00
supervisor: add some comments, remove a no-longer-needed source dependency
This commit is contained in:
@@ -217,7 +217,6 @@
|
||||
C0684DFB2DBFE8130091E774 /* bootstrapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = C06C21332C8793720023E9D9 /* bootstrapping.swift */; };
|
||||
C0684DFC2DBFE8130091E774 /* bootstrapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = C06C21332C8793720023E9D9 /* bootstrapping.swift */; };
|
||||
C0684E212DBFF81B0091E774 /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = C0684E202DBFF81B0091E774 /* ArgumentParser */; };
|
||||
C0684E232DC0029B0091E774 /* stderrout.swift in Sources */ = {isa = PBXBuildFile; fileRef = C008A0552D25B20E0073ADBA /* stderrout.swift */; };
|
||||
C0684E252DC008A30091E774 /* UNIXProcessInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = C06C21392C88CA1F0023E9D9 /* UNIXProcessInfo.swift */; };
|
||||
C0684E262DC024480091E774 /* munkilog.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07074DB2C33AE5F00B86310 /* munkilog.swift */; };
|
||||
C0684E272DC024630091E774 /* prefs.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07A6FAF2C2B22A400090743 /* prefs.swift */; };
|
||||
@@ -1752,7 +1751,6 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
C0684E252DC008A30091E774 /* UNIXProcessInfo.swift in Sources */,
|
||||
C0684E232DC0029B0091E774 /* stderrout.swift in Sources */,
|
||||
C0684E272DC024630091E774 /* prefs.swift in Sources */,
|
||||
C0684E262DC024480091E774 /* munkilog.swift in Sources */,
|
||||
C0684E282DC028940091E774 /* constants.swift in Sources */,
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// A basic implementation of the supervisor tool. The Python original was written and
|
||||
// contributed by Google MacOps, and has features that Google may have used, but Munki
|
||||
// did not. This implementation does not support the following options:
|
||||
// --error-exec, --error-exec-exit-codes, or --debug
|
||||
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
|
||||
@@ -32,7 +37,6 @@ private func log(_ message: String) {
|
||||
munkiLog(message, logFile: LOGNAME)
|
||||
}
|
||||
|
||||
|
||||
func signalHandler(_ sig: Int32) -> DispatchSourceSignal {
|
||||
// the intent here is to kill our child process(es) when we get a SIGINT or SIGTERM
|
||||
// (sadly we can't do it for SIGKILL) so they don't keep running if we're stopped
|
||||
@@ -59,6 +63,7 @@ func signalHandler(_ sig: Int32) -> DispatchSourceSignal {
|
||||
return sigSrc
|
||||
}
|
||||
|
||||
/// A class to run a process and kill it if it runs too long
|
||||
class SupervisorProcessRunner {
|
||||
let task = Process()
|
||||
var timeout: Int = 0
|
||||
@@ -126,6 +131,8 @@ class SupervisorProcessRunner {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// A class to supervise a running process, optionally sleeping a random number of seconds before starting the process
|
||||
class Supervisor {
|
||||
var timeout: Int
|
||||
var delayRandom: Int
|
||||
@@ -154,7 +161,9 @@ class Supervisor {
|
||||
log("Sleeping for \(randomDelay) seconds...")
|
||||
usleep(useconds_t(randomDelay * 1_000_000))
|
||||
}
|
||||
return await SupervisorProcessRunner(command, arguments: arguments, timeout: timeout).run()
|
||||
return await SupervisorProcessRunner(command,
|
||||
arguments: arguments,
|
||||
timeout: timeout).run()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user