Files
i2p.i2p/launchers/macosx/I2PLauncher/Utils/LaunchAgent+Status.swift
meeh 45b4f426a8 OSX Launcher: Big rewrite of swift code where it now has the capability of creating services.
The router management has been much easier with this approach as it uses launchd to do the dirty work.
This code also uses java_home as a wrapper instead of locating the java binary by itself. This also contribute to the improvements.
2018-10-11 16:55:07 +00:00

70 lines
1.5 KiB
Swift

//
// LaunchAgent+Status.swift
// I2PLauncher
//
// Created by Mikal Villa on 05/10/2018.
// Copyright © 2018 The I2P Project. All rights reserved.
//
import Foundation
public enum AgentStatus: Equatable {
case running(pid: Int)
case loaded
case unloaded
public static func ==(lhs: AgentStatus, rhs: AgentStatus) -> Bool {
switch (lhs, rhs) {
case ( let .running(lhpid), let .running(rhpid) ):
return lhpid == rhpid
case (.loaded, .loaded):
return true
case (.unloaded, .unloaded):
return true
default:
return false
}
}
}
extension LaunchAgent {
/// Run `launchctl start` on the agent
///
/// Check the status of the job with `.status()`
public func start() {
LaunchAgentManager.shared.start(self)
}
/// Run `launchctl stop` on the agent
///
/// Check the status of the job with `.status()`
public func stop() {
LaunchAgentManager.shared.stop(self)
}
/// Run `launchctl load` on the agent
///
/// Check the status of the job with `.status()`
public func load() throws {
try LaunchAgentManager.shared.load(self)
}
/// Run `launchctl unload` on the agent
///
/// Check the status of the job with `.status()`
public func unload() throws {
try LaunchAgentManager.shared.unload(self)
}
/// Retreives the status of the LaunchAgent from `launchctl`
///
/// - Returns: the agent's status
public func status() -> AgentStatus {
return LaunchAgentManager.shared.status(self)
}
}