From a8df39483b27ea0566ae4ca4f2aa58ad00f2c06d Mon Sep 17 00:00:00 2001 From: Sebastian Moser Date: Thu, 15 Aug 2024 12:11:25 +0200 Subject: [PATCH] new yt-block with unkillable working --- hosts/main.nix | 4 +++- scripts/yt-block/main.py | 22 ++++++++++++++++++++++ scripts/yt-block/module.nix | 5 +++-- scripts/yt-block/starter.nix | 12 ++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 scripts/yt-block/starter.nix diff --git a/hosts/main.nix b/hosts/main.nix index e2da36b..8df89f6 100644 --- a/hosts/main.nix +++ b/hosts/main.nix @@ -1,5 +1,5 @@ -{ pkgs, lib, workDir, self, secretsDir, config, inputs, ... }: +{ pkgs, lib, workDir, self, secretsDir, config, inputs, system, ... }: { # https://bugzilla.kernel.org/show_bug.cgi?id=110941 @@ -99,6 +99,8 @@ ]; */ + boot.extraModulePackages = [ self.packages.${system}.random.unkillableKernelModule ]; + hardware.bluetooth.settings = { General = { diff --git a/scripts/yt-block/main.py b/scripts/yt-block/main.py index 9066666..2eb4b88 100644 --- a/scripts/yt-block/main.py +++ b/scripts/yt-block/main.py @@ -7,6 +7,7 @@ import os import json import base64 import subprocess +import time YT_TIME_MAX = 90 # in min STATE_FILE = "/etc/yt_block_state" @@ -36,6 +37,10 @@ def main(): if sys.argv[1] == "i" or sys.argv[1] == "info": cmd_info() return + + if sys.argv[1] == "s" or sys.argv[1] == "starter": + cmd_starter() + return print("unknown command!!!!") @@ -254,5 +259,22 @@ def kill_line(line): print("killing pid:", pid) os.system(f"kill {pid}") +def cmd_starter(): + # become a unkillable process and start this pyhton file with arg1=guard every minute + + # make the /dev/unkillable + os.system("mknod /dev/unkillable c 117 0") + os.system("chmod 666 /dev/unkillable") + + # get pid + pid = os.getpid() + + with open("/dev/unkillable", "r") as file: + file.read(pid) + + while True: + os.system(f"python {__file__} guard") + time.sleep(60) + if __name__ == "__main__": main() diff --git a/scripts/yt-block/module.nix b/scripts/yt-block/module.nix index 3c69ed5..20e6813 100644 --- a/scripts/yt-block/module.nix +++ b/scripts/yt-block/module.nix @@ -1,14 +1,15 @@ { pkgs, ... }: let yt_block = pkgs.callPackage ./app.nix {}; + yt_block_starter = pkgs.callPackage ./app.nix {}; in { systemd.services.yt-block = { enable = true; description = "Block Youtube"; serviceConfig = { Restart = "always"; - RestartSec = "60s"; - ExecStart = "${yt_block}/bin/yt_block guard"; + #RestartSec = "60s"; + ExecStart = "${yt_block_starter}/bin/yt_block_starter"; }; wantedBy = [ "multi-user.target" ]; }; diff --git a/scripts/yt-block/starter.nix b/scripts/yt-block/starter.nix new file mode 100644 index 0000000..0897296 --- /dev/null +++ b/scripts/yt-block/starter.nix @@ -0,0 +1,12 @@ +{ pkgs +, ... +}: let + python = pkgs.python3.withPackages (ps: with ps; [pkgs.python311Packages.cryptography]); + python_script = pkgs.writeText "main-py" (builtins.readFile ./main.py); +in pkgs.writeShellApplication { + name = "yt_block_sterter"; + runtimeInputs = with pkgs; [ iptables bash gnugrep ps util-linux ]; + text = '' + ${python}/bin/python ${python_script} starter + ''; +}