source: launchers/macosx/I2PLauncher/Utils/LaunchAgent+Status.swift @ 45b4f42

Last change on this file since 45b4f42 was 45b4f42, checked in by meeh <meeh@…>, 2 years ago

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.

  • Property mode set to 100644
File size: 1.5 KB
Line 
1//
2//  LaunchAgent+Status.swift
3//  I2PLauncher
4//
5//  Created by Mikal Villa on 05/10/2018.
6//  Copyright © 2018 The I2P Project. All rights reserved.
7//
8
9import Foundation
10
11public enum AgentStatus: Equatable {
12 
13  case running(pid: Int)
14  case loaded
15  case unloaded
16 
17  public static func ==(lhs: AgentStatus, rhs: AgentStatus) -> Bool {
18    switch (lhs, rhs) {
19    case ( let .running(lhpid), let .running(rhpid) ):
20      return lhpid == rhpid
21    case (.loaded, .loaded):
22      return true
23    case (.unloaded, .unloaded):
24      return true
25    default:
26      return false
27    }
28  }
29 
30}
31
32extension LaunchAgent {
33 
34  /// Run `launchctl start` on the agent
35  ///
36  /// Check the status of the job with `.status()`
37  public func start() {
38    LaunchAgentManager.shared.start(self)
39  }
40 
41  /// Run `launchctl stop` on the agent
42  ///
43  /// Check the status of the job with `.status()`
44  public func stop() {
45    LaunchAgentManager.shared.stop(self)
46  }
47 
48  /// Run `launchctl load` on the agent
49  ///
50  /// Check the status of the job with `.status()`
51  public func load() throws {
52    try LaunchAgentManager.shared.load(self)
53  }
54 
55  /// Run `launchctl unload` on the agent
56  ///
57  /// Check the status of the job with `.status()`
58  public func unload() throws {
59    try LaunchAgentManager.shared.unload(self)
60  }
61 
62  /// Retreives the status of the LaunchAgent from `launchctl`
63  ///
64  /// - Returns: the agent's status
65  public func status() -> AgentStatus {
66    return LaunchAgentManager.shared.status(self)
67  }
68 
69}
Note: See TracBrowser for help on using the repository browser.