Compare commits

..

5 commits

Author SHA1 Message Date
8e2f3a39a1 Loggear kernel "bien"
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-06-19 09:57:17 -03:00
121207923e Logging 2022-06-18 21:29:00 -03:00
c660c192a0 data: Crear carpetas parientes a los archivos 2022-06-18 21:27:20 -03:00
24a1dd98a8 nginx: Arreglar restart 2022-06-18 15:24:22 -03:00
8437ca9161 dhcpcd: tmpfs /var/run/dhcpcd 2022-06-18 15:24:12 -03:00
6 changed files with 115 additions and 14 deletions

View file

@ -1,5 +1,7 @@
local utils = require "../utils"
local t = require "../utils/templater" local t = require "../utils/templater"
local dirs = {} local dirs = {}
local links = {}
local function generate_mount_data() local function generate_mount_data()
local string = "#!/bin/sh\n" local string = "#!/bin/sh\n"
@ -8,10 +10,12 @@ local function generate_mount_data()
if dir.type == "file" then if dir.type == "file" then
touch(dir.mountpoint) touch(dir.mountpoint)
string = string .. t([[ string = string .. t([[
mkdir -p '{{dirname}}' || exit 1
touch -a '{{path}}' || exit 1 touch -a '{{path}}' || exit 1
mount '{{path}}' '{{mountpoint}}' -o bind,umask=100,uid={{uid}},gid={{gid}} || exit 1 mount '{{path}}' '{{mountpoint}}' -o bind,umask=100,uid={{uid}},gid={{gid}} || exit 1
]], ]],
dir { dirname = utils.dirname(dir.path),
path = dir.path, mountpoint = dir.mountpoint, uid = dir.uid, gid = dir.gid }
) )
elseif dir.type == "dir" then elseif dir.type == "dir" then
mkdir(dir.mountpoint) mkdir(dir.mountpoint)
@ -23,6 +27,16 @@ mount '{{path}}' '{{mountpoint}}' -o bind,umask=100,uid={{uid}},gid={{gid}} || e
) )
end end
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) add_file("/usr/local/bin/mount-data", string)
chmod("/usr/local/bin/mount-data", 700) chmod("/usr/local/bin/mount-data", 700)
end end
@ -40,10 +54,15 @@ local function add_data_file(path, mountpoint, uid, gid)
}) })
generate_mount_data() generate_mount_data()
end end
local function add_data_link(target, path)
table.insert(links, { target = target, path = path })
generate_mount_data()
end
modules.data = { modules.data = {
add_data_dir = add_data_dir, add_data_dir = add_data_dir,
add_data_file = add_data_file, add_data_file = add_data_file,
add_data_link = add_data_link,
} }
mkdir("/data") mkdir("/data")

View file

@ -1,5 +1,6 @@
add_packages({ "dhcpcd" }) add_packages({ "dhcpcd" })
add_symlink("/etc/resolv.conf", "/run/resolv.conf") add_symlink("/etc/resolv.conf", "/run/resolv.conf")
modules.fstab.add_tmpfs("/var/lib/dhcpcd")
modules.runit.add_service("dhcpcd", [[#!/bin/sh modules.runit.add_service("dhcpcd", [[#!/bin/sh
exec dhcpcd --nobackground exec dhcpcd --nobackground
]]) ]])

View file

@ -4,6 +4,6 @@ modules.fstab.add_tmpfs("/var/lib/nginx/tmp")
modules.data.add_data_dir("/data/nginx/logs", "/var/log/nginx", "nginx", "nginx") modules.data.add_data_dir("/data/nginx/logs", "/var/log/nginx", "nginx", "nginx")
modules.runit.add_service("nginx", [[#!/bin/sh modules.runit.add_service("nginx", [[#!/bin/sh
exec 2>&1 exec 2>&1
mkdir /run/nginx || exit 1 mkdir -p /run/nginx || exit 1
exec nginx -g 'daemon off;' exec nginx -g 'daemon off;'
]]) ]])

View file

@ -8,9 +8,23 @@ local function add_executable(path, script)
add_file(path, script) add_file(path, script)
chmod(path, "700") chmod(path, "700")
end 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 params = {name = name}
local run_script_path = t("/etc/sv/{{name}}/run", params) 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_executable(run_script_path, script)
add_symlink("/etc/runit/runsvdir/default/"..name, "/etc/sv/"..name) add_symlink("/etc/runit/runsvdir/default/"..name, "/etc/sv/"..name)
add_symlink( add_symlink(
@ -256,8 +270,6 @@ msg "Setting hostname..."
hostname -F /etc/hostname hostname -F /etc/hostname
]]) ]])
modules.data.add_data_file("/data/dmesg.log", "/var/log/dmesg.log", "root", "root")
-- Initial boot -- Initial boot
add_executable("/etc/runit/1", [[#!/bin/sh add_executable("/etc/runit/1", [[#!/bin/sh
@ -275,13 +287,6 @@ for f in /etc/runit/core-services/*.sh; do
[ -r $f ] && . $f [ -r $f ] && . $f
done done
dmesg >/var/log/dmesg.log
if [ $(sysctl -n kernel.dmesg_restrict 2>/dev/null) -eq 1 ]; then
chmod 0600 /var/log/dmesg.log
else
chmod 0644 /var/log/dmesg.log
fi
# create files for controlling runit # create files for controlling runit
mkdir -p /run/runit mkdir -p /run/runit
install -m000 /dev/null /run/runit/stopit install -m000 /dev/null /run/runit/stopit
@ -357,6 +362,7 @@ fi
add_packages({ "runit", "eudev" }) add_packages({ "runit", "eudev" })
modules.runit.add_service("getty-tty1", [[#!/bin/sh 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 modules.runit.add_service("getty-tty2", [[#!/bin/sh
exec chpst -P getty 38400 tty2 linux]]) exec chpst -P getty 38400 tty2 linux]], false)

74
modules/socklog.lua Normal file
View file

@ -0,0 +1,74 @@
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")
modules.runit.add_service("log-kernel",
[[#!/bin/sh
exec cat /proc/kmsg]],
[[#!/bin/sh
exec logger -p kern.info -t '']])

View file

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