Compare commits
No commits in common. "8e2f3a39a1c839f03c0cd7e889e4cf97d4493101" and "6e69a63a4cabf3f34cc6a36e19bcfac5a09d3af4" have entirely different histories.
8e2f3a39a1
...
6e69a63a4c
6 changed files with 14 additions and 115 deletions
|
@ -1,7 +1,5 @@
|
||||||
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"
|
||||||
|
@ -10,12 +8,10 @@ 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
|
||||||
]],
|
]],
|
||||||
{ dirname = utils.dirname(dir.path),
|
dir
|
||||||
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)
|
||||||
|
@ -27,16 +23,6 @@ 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
|
||||||
|
@ -54,15 +40,10 @@ 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")
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
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
|
||||||
]])
|
]])
|
||||||
|
|
|
@ -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 -p /run/nginx || exit 1
|
mkdir /run/nginx || exit 1
|
||||||
exec nginx -g 'daemon off;'
|
exec nginx -g 'daemon off;'
|
||||||
]])
|
]])
|
||||||
|
|
|
@ -8,23 +8,9 @@ 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, _log)
|
local function add_service(name, script)
|
||||||
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(
|
||||||
|
@ -270,6 +256,8 @@ 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
|
||||||
|
|
||||||
|
@ -287,6 +275,13 @@ 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
|
||||||
|
@ -362,7 +357,6 @@ 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]], false)
|
exec chpst -P getty 38400 tty1 linux]])
|
||||||
modules.runit.add_service("getty-tty2", [[#!/bin/sh
|
modules.runit.add_service("getty-tty2", [[#!/bin/sh
|
||||||
exec chpst -P getty 38400 tty2 linux]], false)
|
exec chpst -P getty 38400 tty2 linux]])
|
||||||
|
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
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 '']])
|
|
|
@ -44,7 +44,6 @@ 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"
|
||||||
|
|
Loading…
Reference in a new issue