Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
tutorial:autorun_options [2018/09/06 08:32]
payonel
tutorial:autorun_options [2018/09/06 17:32]
payonel
Line 112: Line 112:
 This option is really a non-option, documented here to disuade users with reasonable arguments against doing so. This option is really a non-option, documented here to disuade users with reasonable arguments against doing so.
  
-OpenOS runs boot scripts in `/boot/` for its core operations. While it is possible to install custom boot scripts along side the kernel boot scripts, it is quite unadvisable to do so. The boot scripts are executed in a numbered ordered (sorted by their filename).+OpenOS runs boot scripts ​(sorted by their filenames) ​in `/boot/` for its core operations. While it is possible to install custom boot scripts along side the kernel boot scripts, it is quite unadvisable to do so.
  
 Installing a custom boot script (in `/boot/`) poses the risk that your boot script may be run before core libraries are available. There is no gaurantees that even invoking `require` in a boot script is safe in the current version OpenOS, or will be safe in future OpenOS updates (as I may change the boot order). Installing a custom boot script (in `/boot/`) poses the risk that your boot script may be run before core libraries are available. There is no gaurantees that even invoking `require` in a boot script is safe in the current version OpenOS, or will be safe in future OpenOS updates (as I may change the boot order).
  
 There may not be a fully initialized io, there may be an incomplete init process, there may even be incomplete lua libraries. Depending on the code you execute in your boot script, you may even unintentionally circumvent the event dispatching system causing the system to miss component updates. Yes, there is a lot that the boot process is responsible for. There may not be a fully initialized io, there may be an incomplete init process, there may even be incomplete lua libraries. Depending on the code you execute in your boot script, you may even unintentionally circumvent the event dispatching system causing the system to miss component updates. Yes, there is a lot that the boot process is responsible for.
 +
 +With all of that said, here are a couple examples of `/boot` scripts that would work safely now and for the foreseable future. Prefix your script filename 99_ so that it loads at the end of the boot sequence.
 +
 +```lua
 +local event = require("​event"​)
 +-- the init signal is fired by the boot process, means the system is ready
 +event.listen("​init",​ function()
 +  local thread = require("​thread"​)
 +  thread.create(function()
 +    --[[
 +      your custom service code as a background thread
 +    ]]--
 +  end):​detach()
 +end)
 +```
 +
 +```lua
 +local event = require("​event"​)
 +event.listen("​component_added",​ function(...)
 +  --[[
 +    your custom service code as a background event responder
 +  ]]--
 +end)
 +```
  
 Contents Contents