(
config: StandaloneOptions,
certs: &CertificateAuthority,
data_dir: Arc<ServerDataDir>,
db_cores: JobCores,
)
| 61 | |
| 62 | impl StandaloneEnv { |
| 63 | pub async fn init( |
| 64 | config: StandaloneOptions, |
| 65 | certs: &CertificateAuthority, |
| 66 | data_dir: Arc<ServerDataDir>, |
| 67 | db_cores: JobCores, |
| 68 | ) -> anyhow::Result<Arc<Self>> { |
| 69 | let _pid_file = data_dir.pid_file()?; |
| 70 | let meta_path = data_dir.metadata_toml(); |
| 71 | let mut meta = MetadataFile::new("standalone"); |
| 72 | if let Some(existing_meta) = MetadataFile::read(&meta_path).context("failed reading metadata.toml")? { |
| 73 | meta = existing_meta.check_compatibility_and_update(meta, meta_path.as_ref())?; |
| 74 | } |
| 75 | meta.write(&meta_path).context("failed writing metadata.toml")?; |
| 76 | |
| 77 | let control_db = ControlDb::new(&data_dir.control_db()).context("failed to initialize control db")?; |
| 78 | let energy_monitor = Arc::new(NullEnergyMonitor); |
| 79 | let program_store = Arc::new(DiskStorage::new(data_dir.program_bytes().0).await?); |
| 80 | |
| 81 | let persistence_provider = |
| 82 | Arc::new(LocalPersistenceProvider::new(data_dir.clone()).with_durability_config(config.durability)); |
| 83 | let host_controller = HostController::new( |
| 84 | data_dir, |
| 85 | config.db_config, |
| 86 | HostRuntimeConfig::new(config.wasm, config.v8), |
| 87 | program_store.clone(), |
| 88 | energy_monitor, |
| 89 | persistence_provider, |
| 90 | db_cores, |
| 91 | ); |
| 92 | let client_actor_index = ClientActorIndex::new(); |
| 93 | let jwt_keys = certs.get_or_create_keys()?; |
| 94 | |
| 95 | let auth_env = auth::default_auth_environment(jwt_keys, LOCALHOST.into()); |
| 96 | |
| 97 | let metrics_registry = prometheus::Registry::new(); |
| 98 | metrics_registry.register(Box::new(&*WORKER_METRICS)).unwrap(); |
| 99 | metrics_registry.register(Box::new(&*ENGINE_METRICS)).unwrap(); |
| 100 | metrics_registry.register(Box::new(&*DB_METRICS)).unwrap(); |
| 101 | metrics_registry.register(Box::new(&*DATA_SIZE_METRICS)).unwrap(); |
| 102 | |
| 103 | Ok(Arc::new(Self { |
| 104 | control_db, |
| 105 | program_store, |
| 106 | host_controller, |
| 107 | client_actor_index, |
| 108 | metrics_registry, |
| 109 | _pid_file, |
| 110 | auth_provider: auth_env, |
| 111 | websocket_options: config.websocket, |
| 112 | })) |
| 113 | } |
| 114 | |
| 115 | pub fn data_dir(&self) -> &Arc<ServerDataDir> { |
| 116 | &self.host_controller.data_dir |
no test coverage detected