new yt-block with unkillable working
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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"
|
||||
@@ -37,6 +38,10 @@ def main():
|
||||
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()
|
||||
|
||||
@@ -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" ];
|
||||
};
|
||||
|
||||
12
scripts/yt-block/starter.nix
Normal file
12
scripts/yt-block/starter.nix
Normal 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
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user