startup.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package main
  2. /*
  3. System Startup Script for ArOZ Online System
  4. author: tobychui
  5. */
  6. import (
  7. "fmt"
  8. "log"
  9. "os"
  10. db "imuslab.com/arozos/mod/database"
  11. "imuslab.com/arozos/mod/filesystem"
  12. fs "imuslab.com/arozos/mod/filesystem"
  13. "imuslab.com/arozos/mod/info/logger"
  14. )
  15. func RunStartup() {
  16. systemWideLogger, _ = logger.NewLogger("system", "system/logs/system/", true)
  17. //1. Initiate the main system database
  18. //Check if system or web both not exists and web.tar.gz exists. Unzip it for the user
  19. if (!fs.FileExists("system/") || !fs.FileExists("web/")) && fs.FileExists("./web.tar.gz") {
  20. log.Println("[Update] Unzipping system critical files from archive")
  21. extErr := filesystem.ExtractTarGzipFile("./web.tar.gz", "./")
  22. if extErr != nil {
  23. //Extract failed
  24. fmt.Println("▒▒ ERROR: UNABLE TO EXTRACT CRITICAL SYSTEM FOLDERS ▒▒")
  25. fmt.Println(extErr)
  26. panic("Unable to extract content from web.tar.gz to fix the missing system / web folder. Please unzip the web.tar.gz manually.")
  27. }
  28. //Extract success
  29. extErr = os.Remove("./web.tar.gz")
  30. if extErr != nil {
  31. systemWideLogger.PrintAndLog("Update", "Unable to remove web.tar.gz: "+extErr.Error(), extErr)
  32. }
  33. }
  34. if !fs.FileExists("system/") {
  35. fmt.Println("▒▒ ERROR: SYSTEM FOLDER NOT FOUND ▒▒")
  36. 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.")
  37. }
  38. if !fs.FileExists("web/") {
  39. fmt.Println("▒▒ ERROR: WEB FOLDER NOT FOUND ▒▒")
  40. 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.")
  41. }
  42. dbconn, err := db.NewDatabase("system/ao.db", false)
  43. if err != nil {
  44. panic(err)
  45. }
  46. sysdb = dbconn
  47. //2. Initiate the auth Agent
  48. AuthInit() //See auth.go
  49. //3. Start Permission Management Module
  50. permissionNewHandler() //See permission.go
  51. //4. Mount and create the storage system base
  52. StorageInit() //See storage.go
  53. //5. Startup user and permission sytem
  54. UserSystemInit() //See user.go
  55. permissionInit() //Register permission interface after user
  56. RegisterSystemInit() //See register.go
  57. GroupStoragePoolInit() //Register permission groups's storage pool, require permissionInit()
  58. BridgeStoragePoolInit() //Register the bridged storage pool based on mounted storage pools
  59. //6. Start Modules and Package Manager
  60. ModuleServiceInit() //Module Handler
  61. PackagManagerInit() //Start APT service agent
  62. //7. Kickstart the File System and Desktop
  63. NightlyTasksInit() //Start Nightly task scheduler
  64. FileSystemInit() //Start FileSystem
  65. DesktopInit() //Start Desktop
  66. //StorageDaemonInit() //Start File System handler daemon (for backup and other sync process)
  67. //8 Start AGI and Subservice modules (Must start after module)
  68. AGIInit() //ArOZ Javascript Gateway Interface, must start after fs
  69. SchedulerInit() //Start System Scheudler
  70. SubserviceInit() //Subservice Handler
  71. //9. Initiate System Settings Handlers
  72. SystemSettingInit() //Start System Setting Core
  73. DiskQuotaInit() //Disk Quota Management
  74. DiskServiceInit() //Start Disk Services
  75. DeviceServiceInit() //Client Device Management
  76. SystemInfoInit() //System Information UI
  77. SystemIDInit() //System UUID Manager
  78. AuthSettingsInit() //Authentication Settings Handler, must be start after user Handler
  79. AdvanceSettingInit() //System Advance Settings
  80. StartupFlagsInit() //System BootFlag settibg
  81. HardwarePowerInit() //Start host power manager
  82. RegisterStorageSettings() //Storage Settings
  83. //10. Startup network services and schedule services
  84. NetworkServiceInit() //Initalize network serves (ssdp / mdns etc)
  85. WiFiInit() //Inialize WiFi management module
  86. //ARSM Moved to scheduler, remote support is rewrite pending
  87. //ArsmInit() //Inialize ArOZ Remote Support & Management Framework
  88. //11. Other stuffs
  89. util_init()
  90. system_resetpw_init()
  91. mediaServer_init()
  92. security_init()
  93. storageHeartbeatTickerInit()
  94. OAuthInit() //Oauth system init
  95. ldapInit() //LDAP system init
  96. notificationInit() //Notification system init
  97. //Start High Level Services that requires full arozos architectures
  98. FileServerInit()
  99. //FTPServerInit() //Start FTP Server Endpoints
  100. //WebDAVInit() //Start WebDAV Endpoint
  101. ClusterInit() //Start Cluster Services
  102. IoTHubInit() //Inialize ArozOS IoT Hub module
  103. ModuleInstallerInit() //Start Module Installer
  104. //Finally
  105. moduleHandler.ModuleSortList() //Sort the system module list
  106. }