startup.go 4.9 KB

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