startup.go 4.5 KB

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