new yt-block with unkillable working

This commit is contained in:
Sebastian Moser
2024-08-15 12:11:25 +02:00
parent def6f557d5
commit a8df39483b
4 changed files with 40 additions and 3 deletions

View File

@@ -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 = {

View File

@@ -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()

View File

@@ -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" ];
};

View File

@@ -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
'';
}