This commit is contained in:
Cat /dev/Nulo 2022-06-18 21:29:00 -03:00
parent c660c192a0
commit 121207923e
4 changed files with 103 additions and 3 deletions

View File

@ -1,6 +1,7 @@
local utils = require "../utils"
local t = require "../utils/templater"
local dirs = {}
local links = {}
local function generate_mount_data()
local string = "#!/bin/sh\n"
@ -26,6 +27,16 @@ mount '{{path}}' '{{mountpoint}}' -o bind,umask=100,uid={{uid}},gid={{gid}} || e
)
end
end
for i=1,#links do
local link = links[i]
string = string .. t([[
mkdir -p '{{dirname}}' || exit 1
ln -s '{{target}}' '{{path}}' || exit 1
]],
{ dirname = utils.dirname(link.path),
target = link.target, path = link.path }
)
end
add_file("/usr/local/bin/mount-data", string)
chmod("/usr/local/bin/mount-data", 700)
end
@ -43,10 +54,15 @@ local function add_data_file(path, mountpoint, uid, gid)
})
generate_mount_data()
end
local function add_data_link(target, path)
table.insert(links, { target = target, path = path })
generate_mount_data()
end
modules.data = {
add_data_dir = add_data_dir,
add_data_file = add_data_file,
add_data_link = add_data_link,
}
mkdir("/data")

View File

@ -8,9 +8,23 @@ local function add_executable(path, script)
add_file(path, script)
chmod(path, "700")
end
local function add_service(name, script)
local function add_service(name, script, _log)
local log = _log == nil and true or _log
local params = {name = name}
local run_script_path = t("/etc/sv/{{name}}/run", params)
if log then
local log_script_path = t("/etc/sv/{{name}}/log/run", params)
if log == true then
add_executable(log_script_path, t([[#!/bin/sh
exec logger -p daemon.info -t {{name}}]], params))
else
add_executable(log_script_path, log)
end
add_symlink(
t("/etc/sv/{{name}}/log/supervise", params),
t("/run/runit/supervise.{{name}}.log", params)
)
end
add_executable(run_script_path, script)
add_symlink("/etc/runit/runsvdir/default/"..name, "/etc/sv/"..name)
add_symlink(
@ -357,6 +371,7 @@ fi
add_packages({ "runit", "eudev" })
modules.runit.add_service("getty-tty1", [[#!/bin/sh
exec chpst -P getty 38400 tty1 linux]])
exec chpst -P getty 38400 tty1 linux]], false)
modules.runit.add_service("getty-tty2", [[#!/bin/sh
exec chpst -P getty 38400 tty2 linux]])
exec chpst -P getty 38400 tty2 linux]], false)

68
modules/socklog.lua Normal file
View File

@ -0,0 +1,68 @@
add_packages({ "socklog" })
-- Thanks to https://github.com/void-linux/socklog-void
modules.runit.add_service("socklog-unix",
[[#!/bin/sh
exec chpst -U nobody:nogroup socklog unix /dev/log 2>&1]],
[[#!/bin/sh
exec svlogd -ttt /var/log/socklog/*]])
modules.data.add_data_dir("/data/socklog/", "/var/log/socklog", "root", "root")
add_file("/etc/socklog/everything", [[!syslog-stripdate
-auth.*
-authpriv.*]])
modules.data.add_data_link("/etc/socklog/everything", "/var/log/socklog/everything/config")
-- TODO: package
add_file("/usr/local/bin/svlogtail", [[#!/bin/sh
usage () {
cat <<-'EOF'
svlogtail [-f] [LOG...] - show svlogd logs conveniently
Without arguments, show current logs of all services, uniquely.
With arguments, show all logs of mentioned services
With -f, follow log output.
EOF
}
globexist() {
[ -f "$1" ]
}
IFS='
'
fflag=false
if [ "$1" = -f ]; then
shift
fflag=true
fi
if [ $# = 0 ]; then
cat /var/log/socklog/*/current | sort -u
if $fflag; then
tail -Fq -n0 /var/log/socklog/*/current | uniq
fi
else
old=
cur=
for log; do
case "$log" in
-*) usage; exit 1;;
esac
if [ -d /var/log/socklog/$log ]; then
if globexist /var/log/socklog/$log/*.[us]; then
old="$old$IFS/var/log/socklog/$log/*.[us]"
fi
cur="$cur$IFS/var/log/socklog/$log/current"
else
echo "no logs for $log" 1>&2
exit 1
fi
done
cat $old $cur | sort
if $fflag; then
tail -Fq -n0 $cur
fi
fi]])
chmod("/usr/local/bin/svlogtail", "700")

View File

@ -44,6 +44,7 @@ module "fstab"
module "data"
module "kernel"
module "runit"
module "socklog"
module "hostname"
module "dhcpcd"
module "nginx"