Compare commits

...

4 commits

Author SHA1 Message Date
f
dc0a3257fc NTPSec 2022-09-26 16:04:32 -03:00
f
c5d95d0e5e Static routing.
OVH network assigns IP addresses on a /32 subnet, so we can't add a
default gateway because it's outside the subnet.
2022-09-26 16:04:20 -03:00
f
f05200bffc Git support 2022-09-26 16:00:09 -03:00
f
9064e5304f allow ntpsec to set the date even if it's too old 2022-09-03 19:23:37 -03:00
7 changed files with 93 additions and 15 deletions

View file

@ -24,6 +24,8 @@ packages:
- "ntpsec"
- "haveged"
- "haveged-openrc"
- "git"
- "git-lfs"
templates:
- "/etc/conf.d/iptables"
- "/etc/conf.d/ip6tables"
@ -38,6 +40,8 @@ templates:
- "/etc/sysctl.d/coredump.conf"
- "/etc/docker/daemon.json"
- "/etc/ntp.conf"
executables:
- "/usr/libexec/ifupdown-ng/routes"
services:
- runlevel: "sysinit"
service: "devfs"

View file

@ -9,6 +9,12 @@
dest: "/mnt{{ item }}"
mode: "640"
loop: "{{ templates }}"
- name: "Also executables."
template:
src: "templates{{ item }}.j2"
dest: "/mnt{{ item }}"
mode: "750"
loop: "{{ executables }}"
- name: "And services."
template:
src: "templates{{ item }}.j2"

View file

@ -7,6 +7,12 @@
dest: "{{ item }}"
mode: "640"
loop: "{{ templates }}"
- name: "Also executables."
template:
src: "templates{{ item }}.j2"
dest: "{{ item }}"
mode: "750"
loop: "{{ executables }}"
- name: "And services."
template:
src: "templates{{ item }}.j2"

View file

@ -1,20 +1,9 @@
#!/sbin/openrc-run
DAEMON="/usr/sbin/ntpd"
PIDFILE="/var/run/ntpd.pid"
command="/usr/sbin/ntpd"
pidfile="/var/run/ntpd.pid"
command_args="-g"
depend() {
need net
}
start() {
ebegin "Starting NTPSec"
start-stop-daemon --start --exec "${DAEMON}" --pidfile "${PIDFILE}"
eend $?
}
stop() {
ebegin "Stopping NTPSec"
start-stop-daemon --stop --pidfile "${PIDFILE}"
eend $?
}

View file

@ -6,7 +6,7 @@ auto eth0
iface eth0 inet static
address {{ ansible_host }}/{{ netmask }}
gateway {{ gateway }}
routes-static {{ gateway }},default via {{ gateway }}
{% if ip6 is defined %}
iface eth0 inet6 static

View file

@ -1,3 +1,4 @@
# https://gist.github.com/jauderho/2ad0d441760fc5ed69d8d4e2d6b35f8d
server time.cloudflare.com nts iburst
driftfile /var/lib/ntp/ntp.drift
file pidfile filename /var/run/ntpd.pid type pid

View file

@ -0,0 +1,72 @@
#!/bin/sh
# https://github.com/ifupdown-ng/ifupdown-ng/issues/42#issuecomment-849135927
[ -z "${VERBOSE}" ] || set -x
# routes-static 1.2.3.0/24,10.0.0.0/8 via 1.2.3.4
# routes-rule dport 25 table 123,dport 587 table 123
# adds $3 to $1 if $1 does not contain $2
addif() {
if [ "$1" = "${1%$2*}" ]; then
echo $1 $3
else
echo $1
fi
}
decidr() {
echo "${1%/*}"
}
addsrc() {
addif "$1" src "src $(decidr $IF_ADDRESS)"
}
adddev() {
addif "$1" dev "dev $IFACE"
}
# $1: input string
# $2: delimeter
# $3: function to call
foreach() {
list="$1"
while [ -n "$list" ]; do
line="${list%%$2*}"
list="${list#*$2}"
"$3" "$line"
[ "$line" = "$list" ] && break
done
}
# add a route
prep() {
route="$1"
route=$(addsrc "$route")
route=$(adddev "$route")
echo $route
}
routeadd() {
${MOCK} ip route add $(prep "$1")
}
routedel() {
${MOCK} ip route del $(prep "$1")
}
ruleadd() {
${MOCK} ip rule add $1
}
ruledel() {
${MOCK} ip rule del $1
}
case "$PHASE" in
up)
foreach "$IF_ROUTES_STATIC" , routeadd
foreach "$IF_ROUTES_RULE" , ruleadd
;;
down)
foreach "$IF_ROUTES_STATIC" , routedel
foreach "$IF_ROUTES_RULE" , ruledel
;;
*) exit 0 ;;
esac