@@ -43,16 +43,11 @@ struct APIServer: AsyncParsableCommand {
4343 @Flag ( name: . long, help: " Enable debug logging " )
4444 var debug = false
4545
46- @Option ( name: . shortAndLong, help: " Daemon root directory " )
47- var root = Self . appRoot. path
46+ var appRoot = ApplicationRoot . url
4847
49- static let appRoot : URL = {
50- FileManager . default. urls (
51- for: . applicationSupportDirectory,
52- in: . userDomainMask
53- ) . first!
54- . appendingPathComponent ( " com.apple.container " )
55- } ( )
48+ static func releaseVersion( ) -> String {
49+ ( Bundle . main. infoDictionary ? [ " CFBundleShortVersionString " ] as? String ) ?? get_release_version ( ) . map { String ( cString: $0) } ?? " 0.0.0 "
50+ }
5651
5752 func run( ) async throws {
5853 let commandName = Self . configuration. commandName ?? " container-apiserver "
@@ -64,20 +59,18 @@ struct APIServer: AsyncParsableCommand {
6459
6560 do {
6661 log. info ( " configuring XPC server " )
67- let root = URL ( filePath: root)
6862 var routes = [ XPCRoute: XPCServer . RouteHandler] ( )
6963 let pluginLoader = try initializePluginLoader ( log: log)
7064 try await initializePlugins ( pluginLoader: pluginLoader, log: log, routes: & routes)
71- let containersService = try initializeContainerService ( root : root , pluginLoader: pluginLoader, log: log, routes: & routes)
65+ let containersService = try initializeContainerService ( pluginLoader: pluginLoader, log: log, routes: & routes)
7266 let networkService = try await initializeNetworkService (
73- root: root,
7467 pluginLoader: pluginLoader,
7568 log: log,
7669 routes: & routes
7770 )
7871 initializeHealthCheckService ( log: log, routes: & routes)
7972 try initializeKernelService ( log: log, routes: & routes)
80- try initializeVolumeService ( root : root , containersService: containersService, log: log, routes: & routes)
73+ try initializeVolumeService ( containersService: containersService, log: log, routes: & routes)
8174
8275 let server = XPCServer (
8376 identifier: " com.apple.container.apiserver " ,
@@ -134,7 +127,10 @@ struct APIServer: AsyncParsableCommand {
134127 . deletingLastPathComponent ( )
135128 . appendingPathComponent ( " .. " )
136129 . standardized
137- let pluginsURL = PluginLoader . userPluginsDir ( root: installRoot)
130+ log. info ( " initializing plugin loader " , metadata: [ " installRoot " : " \( installRoot. path ( percentEncoded: false ) ) " ] )
131+
132+ let pluginsURL = PluginLoader . userPluginsDir ( installRoot: installRoot)
133+ log. info ( " detecting user plugins directory " , metadata: [ " path " : " \( pluginsURL. path ( percentEncoded: false ) ) " ] )
138134 var directoryExists : ObjCBool = false
139135 _ = FileManager . default. fileExists ( atPath: pluginsURL. path, isDirectory: & directoryExists)
140136 let userPluginsURL = directoryExists. boolValue ? pluginsURL : nil
@@ -161,10 +157,19 @@ struct APIServer: AsyncParsableCommand {
161157 AppBundlePluginFactory ( ) ,
162158 ]
163159
164- log. info ( " PLUGINS: \( pluginDirectories) " )
165- let statePath = PluginLoader . defaultPluginResourcePath ( root: Self . appRoot)
160+ for pluginDirectory in pluginDirectories {
161+ log. info ( " discovered plugin directory " , metadata: [ " path " : " \( pluginDirectory. path ( percentEncoded: false ) ) " ] )
162+ }
163+
164+ let statePath = PluginLoader . defaultPluginResourcePath ( root: appRoot)
166165 try FileManager . default. createDirectory ( at: statePath, withIntermediateDirectories: true )
167- return PluginLoader ( pluginDirectories: pluginDirectories, pluginFactories: pluginFactories, defaultResourcePath: statePath, log: log)
166+ return PluginLoader (
167+ appRoot: appRoot,
168+ pluginDirectories: pluginDirectories,
169+ pluginFactories: pluginFactories,
170+ defaultResourcePath: statePath,
171+ log: log
172+ )
168173 }
169174
170175 // First load all of the plugins we can find. Then just expose
@@ -188,20 +193,20 @@ struct APIServer: AsyncParsableCommand {
188193 }
189194
190195 private func initializeHealthCheckService( log: Logger , routes: inout [ XPCRoute : XPCServer . RouteHandler ] ) {
191- let svc = HealthCheckHarness ( log: log)
196+ let svc = HealthCheckHarness ( appRoot : appRoot , log: log)
192197 routes [ XPCRoute . ping] = svc. ping
193198 }
194199
195200 private func initializeKernelService( log: Logger , routes: inout [ XPCRoute : XPCServer . RouteHandler ] ) throws {
196- let svc = try KernelService ( log: log, appRoot: Self . appRoot)
201+ let svc = try KernelService ( log: log, appRoot: appRoot)
197202 let harness = KernelHarness ( service: svc, log: log)
198203 routes [ XPCRoute . installKernel] = harness. install
199204 routes [ XPCRoute . getDefaultKernel] = harness. getDefaultKernel
200205 }
201206
202- private func initializeContainerService( root : URL , pluginLoader: PluginLoader , log: Logger , routes: inout [ XPCRoute : XPCServer . RouteHandler ] ) throws -> ContainersService {
207+ private func initializeContainerService( pluginLoader: PluginLoader , log: Logger , routes: inout [ XPCRoute : XPCServer . RouteHandler ] ) throws -> ContainersService {
203208 let service = try ContainersService (
204- root : root ,
209+ appRoot : appRoot ,
205210 pluginLoader: pluginLoader,
206211 log: log
207212 )
@@ -217,12 +222,11 @@ struct APIServer: AsyncParsableCommand {
217222 }
218223
219224 private func initializeNetworkService(
220- root: URL ,
221225 pluginLoader: PluginLoader ,
222226 log: Logger ,
223227 routes: inout [ XPCRoute : XPCServer . RouteHandler ]
224228 ) async throws -> NetworksService {
225- let resourceRoot = root . appendingPathComponent ( " networks " )
229+ let resourceRoot = appRoot . appendingPathComponent ( " networks " )
226230 let service = try await NetworksService (
227231 pluginLoader: pluginLoader,
228232 resourceRoot: resourceRoot,
@@ -245,8 +249,8 @@ struct APIServer: AsyncParsableCommand {
245249 return service
246250 }
247251
248- private func initializeVolumeService( root : URL , containersService: ContainersService , log: Logger , routes: inout [ XPCRoute : XPCServer . RouteHandler ] ) throws {
249- let resourceRoot = root . appendingPathComponent ( " volumes " )
252+ private func initializeVolumeService( containersService: ContainersService , log: Logger , routes: inout [ XPCRoute : XPCServer . RouteHandler ] ) throws {
253+ let resourceRoot = appRoot . appendingPathComponent ( " volumes " )
250254 let service = try VolumesService ( resourceRoot: resourceRoot, containersService: containersService, log: log)
251255 let harness = VolumesHarness ( service: service, log: log)
252256
@@ -255,8 +259,4 @@ struct APIServer: AsyncParsableCommand {
255259 routes [ XPCRoute . volumeList] = harness. list
256260 routes [ XPCRoute . volumeInspect] = harness. inspect
257261 }
258-
259- private static func releaseVersion( ) -> String {
260- ( Bundle . main. infoDictionary ? [ " CFBundleShortVersionString " ] as? String ) ?? get_release_version ( ) . map { String ( cString: $0) } ?? " 0.0.0 "
261- }
262262}
0 commit comments