Can I use lua to write Init Scripts?

It seems to have better performance than bash and is more grammatically friendly.

Technically yes, they're just executables. They do have to conform to an expected API though, means they should support the enable, disable, enabled, status, start, stop, restart and reload actions.

Some tools will also scan the init script source for information, mainly to extract the start and stop priority values, for that the Lua init script should contain a multiline comment in a form like:

#!/usr/bin/lua

--[[
# These are dummy values provided for compatibility

START=35
STOP=15
]]

if arg[1] == "enable" then
  -- handle enable action
elseif arg[1] == "disable" then
  -- handle disable action
elseif arg[1] == "start" then
  -- handle start action
elseif ... then
  ...
end
1 Like

And be aware that lua as an interpreter installed by default is on the way out, luci is slowly but steadily dropping its dependencies on lua. Therefore you can't count on it being installed forever - and especially during the earlier boot stages, you might get into a catch with mount_root (if lua is only pulled in via dependencies and resides on the overlay, rather than the squashfs).

1 Like