startup.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package main
  2. /*
  3. System Startup Script for ArOZ Online System
  4. author: tobychui
  5. */
  6. import (
  7. "encoding/json"
  8. "fmt"
  9. "os"
  10. "path/filepath"
  11. db "imuslab.com/arozos/mod/database"
  12. "imuslab.com/arozos/mod/filesystem"
  13. fs "imuslab.com/arozos/mod/filesystem"
  14. "imuslab.com/arozos/mod/info/logger"
  15. )
  16. // vendorInfo holds optional vendor overrides loaded from vendor_info.json.
  17. type vendorInfo struct {
  18. Vendor string `json:"vendor"`
  19. VendorURL string `json:"url"`
  20. Model string `json:"model"`
  21. ModelDesc string `json:"desc"`
  22. }
  23. // loadVendorInfo reads vendor_info.json from vendorResRoot and overrides the
  24. // deviceVendor / deviceVendorURL / deviceModel / deviceModelDesc globals when
  25. // the file is present and valid. Missing fields are left at their defaults.
  26. func loadVendorInfo() {
  27. vendorInfoPath := filepath.Join(vendorResRoot, "vendor_info.json")
  28. if !fs.FileExists(vendorInfoPath) {
  29. return
  30. }
  31. content, err := os.ReadFile(vendorInfoPath)
  32. if err != nil {
  33. logger.PrintAndLog("Vendor", "Failed to read vendor_info.json", err)
  34. return
  35. }
  36. var info vendorInfo
  37. if err := json.Unmarshal(content, &info); err != nil {
  38. logger.PrintAndLog("Vendor", "Failed to parse vendor_info.json", err)
  39. return
  40. }
  41. if info.Vendor != "" {
  42. deviceVendor = info.Vendor
  43. }
  44. if info.VendorURL != "" {
  45. deviceVendorURL = info.VendorURL
  46. }
  47. if info.Model != "" {
  48. deviceModel = info.Model
  49. }
  50. if info.ModelDesc != "" {
  51. deviceModelDesc = info.ModelDesc
  52. }
  53. logger.PrintAndLog("Vendor", "Vendor info loaded from "+vendorInfoPath, nil)
  54. }
  55. func RunStartup() {
  56. systemWideLogger, _ = logger.NewLogger("system", "system/logs/system/", true)
  57. logger.SetDefaultLogger(systemWideLogger)
  58. loadVendorInfo()
  59. //1. Initiate the main system database
  60. //Check if system or web both not exists and web.tar.gz exists. Unzip it for the user
  61. if (!fs.FileExists("system/") || !fs.FileExists("web/")) && fs.FileExists("./web.tar.gz") {
  62. systemWideLogger.PrintAndLog("System", "[Update] Unzipping system critical files from archive", nil)
  63. extErr := filesystem.ExtractTarGzipFile("./web.tar.gz", "./")
  64. if extErr != nil {
  65. //Extract failed
  66. fmt.Println("▒▒ ERROR: UNABLE TO EXTRACT CRITICAL SYSTEM FOLDERS ▒▒")
  67. fmt.Println(extErr)
  68. panic("Unable to extract content from web.tar.gz to fix the missing system / web folder. Please unzip the web.tar.gz manually.")
  69. }
  70. //Extract success
  71. extErr = os.Remove("./web.tar.gz")
  72. if extErr != nil {
  73. systemWideLogger.PrintAndLog("Update", "Unable to remove web.tar.gz: "+extErr.Error(), extErr)
  74. }
  75. }
  76. if !fs.FileExists("system/") {
  77. fmt.Println("▒▒ ERROR: SYSTEM FOLDER NOT FOUND ▒▒")
  78. panic("This error occurs because the system folder is missing. Please follow the installation guide and don't just download a binary and run it.")
  79. }
  80. if !fs.FileExists("web/") {
  81. fmt.Println("▒▒ ERROR: WEB FOLDER NOT FOUND ▒▒")
  82. panic("This error occurs because the web folder is missing. Please follow the installation guide and don't just download a binary and run it.")
  83. }
  84. dbconn, err := db.NewDatabase("system/ao.db", false)
  85. if err != nil {
  86. panic(err)
  87. }
  88. sysdb = dbconn
  89. //2. Initiate the auth Agent
  90. AuthInit() //See auth.go
  91. //3. Start Permission Management Module
  92. permissionNewHandler() //See permission.go
  93. //4. Mount and create the storage system base
  94. RAIDServiceInit() //See disk.go, this must run before Storage Init
  95. StorageInit() //See storage.go
  96. //5. Startup user and permission sytem
  97. UserSystemInit() //See user.go
  98. permissionInit() //Register permission interface after user
  99. RegisterSystemInit() //See register.go
  100. GroupStoragePoolInit() //Register permission groups's storage pool, require permissionInit()
  101. BridgeStoragePoolInit() //Register the bridged storage pool based on mounted storage pools
  102. //6. Start Modules and Package Manager
  103. ModuleServiceInit() //Module Handler
  104. PackagManagerInit() //Start APT service agent
  105. //7. Kickstart the File System and Desktop
  106. NightlyTasksInit() //Start Nightly task scheduler
  107. FileSystemInit() //Start FileSystem
  108. DesktopInit() //Start Desktop
  109. //StorageDaemonInit() //Start File System handler daemon (for backup and other sync process)
  110. //8 Start AGI and Subservice modules (Must start after module)
  111. AGIInit() //ArOZ Javascript Gateway Interface, must start after fs
  112. SchedulerInit() //Start System Scheudler
  113. SubserviceInit() //Subservice Handler
  114. ArozcastInit() //Arozcast remote projection pub/sub relay
  115. //9. Initiate System Settings Handlers
  116. SystemSettingInit() //Start System Setting Core
  117. DiskQuotaInit() //Disk Quota Management
  118. DiskServiceInit() //Start Disk Services
  119. DeviceServiceInit() //Client Device Management
  120. SystemIDInit() //System UUID Manager
  121. SystemInfoInit() //System Information UI
  122. AuthSettingsInit() //Authentication Settings Handler, must be start after user Handler
  123. AdvanceSettingInit() //System Advance Settings
  124. AIModelSettingInit() //AI Model (OpenAI / Anthropic) config, pricing, quota & usage metrics
  125. AGIRuntimeManagerInit() //AGI VM lifecycle monitor (Developer Options tab)
  126. StartupFlagsInit() //System BootFlag settibg
  127. HardwarePowerInit() //Start host power manager
  128. RegisterStorageSettings() //Storage Settings
  129. //10. Startup network services and schedule services
  130. NetworkServiceInit() //Initalize network serves (ssdp / mdns etc)
  131. WiFiInit() //Inialize WiFi management module
  132. //ARSM Moved to scheduler, remote support is rewrite pending
  133. //ArsmInit() //Inialize ArOZ Remote Support & Management Framework
  134. //11. Other stuffs
  135. util_init()
  136. system_resetpw_init()
  137. mediaServer_init()
  138. security_init()
  139. storageHeartbeatTickerInit()
  140. OAuthInit() //Oauth system init
  141. ldapInit() //LDAP system init
  142. notificationInit() //Notification system init
  143. //Start High Level Services that requires full arozos architectures
  144. FileServerInit()
  145. //FTPServerInit() //Start FTP Server Endpoints
  146. //WebDAVInit() //Start WebDAV Endpoint
  147. ClusterInit() //Start Cluster Services
  148. IoTHubInit() //Inialize ArozOS IoT Hub module
  149. ModuleInstallerInit() //Start Module Installer
  150. //Finally
  151. moduleHandler.ModuleSortList() //Sort the system module list
  152. }