From 34cba9f52876dd1b0026c1ed6d7ab3796926c79d Mon Sep 17 00:00:00 2001 From: nachoparker Date: Mon, 14 Jan 2019 20:39:40 -0700 Subject: [PATCH] nc-automount: add delays to some services in a persistent way --- bin/ncp/NETWORKING/NFS.sh | 3 --- bin/ncp/SECURITY/fail2ban.sh | 3 --- bin/ncp/SYSTEM/nc-automount.sh | 34 ++++++++++++++++++++++++++++++---- bin/ncp/SYSTEM/nc-swapfile.sh | 2 -- changelog.md | 6 ++++-- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/bin/ncp/NETWORKING/NFS.sh b/bin/ncp/NETWORKING/NFS.sh index 24e133c2e..e04cc5b77 100644 --- a/bin/ncp/NETWORKING/NFS.sh +++ b/bin/ncp/NETWORKING/NFS.sh @@ -15,9 +15,6 @@ install() apt-get install --no-install-recommends -y nfs-kernel-server systemctl disable nfs-kernel-server systemctl mask nfs-blkmap - - # delay init because of automount - sed -i 's|^ExecStartPre=.*|ExecStartPre=/bin/bash -c "/bin/sleep 30; /usr/sbin/exportfs -r"|' /lib/systemd/system/nfs-server.service } configure() diff --git a/bin/ncp/SECURITY/fail2ban.sh b/bin/ncp/SECURITY/fail2ban.sh index e58a2dac3..40edec452 100644 --- a/bin/ncp/SECURITY/fail2ban.sh +++ b/bin/ncp/SECURITY/fail2ban.sh @@ -56,9 +56,6 @@ EOF grep -q actionstart_ "$F" || sed -i 's|actionstart|actionstart_|' "$F" grep -q actionstop_ "$F" || sed -i 's|actionstop|actionstop_|' "$F" - # delay init because of automount - sed -i "/^ExecStart=/iExecStartPre=/bin/sleep 10" /lib/systemd/system/fail2ban.service - } configure() diff --git a/bin/ncp/SYSTEM/nc-automount.sh b/bin/ncp/SYSTEM/nc-automount.sh index fd3bde8b1..89789aa96 100644 --- a/bin/ncp/SYSTEM/nc-automount.sh +++ b/bin/ncp/SYSTEM/nc-automount.sh @@ -80,10 +80,6 @@ inotifywait --monitor --event create --event delete --format '%f %e' /media/ | \ done EOF chmod +x /usr/local/etc/nc-automount-links-mon - - # delay init because of automount - sed -i "/^ExecStart=/iExecStartPre=/bin/sleep 20" /lib/systemd/system/mariadb.service - sed -i 's|^Restart=.*|Restart=on-failure|' /lib/systemd/system/mariadb.service } configure() @@ -93,6 +89,8 @@ configure() systemctl stop nc-automount-links systemctl disable nc-automount systemctl disable nc-automount-links + rm -rf /etc/systemd/system/{mariadb,nfs-server,dphys-swapfile,fail2ban}.service.d + systemctl daemon-reload echo "automount disabled" return 0 } @@ -100,6 +98,34 @@ configure() systemctl enable nc-automount-links systemctl start nc-automount systemctl start nc-automount-links + + # create delays in some units + mkdir -p /etc/systemd/system/mariadb.service.d + cat > /etc/systemd/system/mariadb.service.d/ncp-delay-automount.conf <<'EOF' +[Service] +ExecStartPre=/bin/sleep 20 +Restart=on-failure +EOF + + mkdir -p /etc/systemd/system/nfs-server.service.d + cat > /etc/systemd/system/nfs-server.service.d/ncp-delay-automount.conf <<'EOF' +[Service] +ExecStartPre=/bin/bash -c "/bin/sleep 30; /usr/sbin/exportfs -r" +EOF + + mkdir -p /etc/systemd/system/dphys-swapfile.service.d + cat > /etc/systemd/system/dphys-swapfile.service.d/ncp-delay-automount.conf <<'EOF' +[Service] +ExecStartPre=/bin/sleep 30 +EOF + + mkdir -p /etc/systemd/system/fail2ban.service.d + cat > /etc/systemd/system/fail2ban.service.d/ncp-delay-automount.conf <<'EOF' +[Service] +ExecStartPre=/bin/sleep 10 +EOF + + systemctl daemon-reload echo "automount enabled" } diff --git a/bin/ncp/SYSTEM/nc-swapfile.sh b/bin/ncp/SYSTEM/nc-swapfile.sh index f74813f87..48f8de7ce 100644 --- a/bin/ncp/SYSTEM/nc-swapfile.sh +++ b/bin/ncp/SYSTEM/nc-swapfile.sh @@ -49,8 +49,6 @@ install() { apt-get update DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends dphys-swapfile - # delay init because of automount - sed -i "/\