summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2022-02-19 15:14:23 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2022-02-19 15:14:23 +0100
commit096de7c4be93f65372a38cc0ec87a8bb9e947f0c (patch)
treeec6a64ee785859fb3f29bec58b41e71ed75d16fa /modules
parent67c8c17009f0cbc02e4638e491ec09592c0de274 (diff)
downloadnixos-096de7c4be93f65372a38cc0ec87a8bb9e947f0c.tar
nixos-096de7c4be93f65372a38cc0ec87a8bb9e947f0c.tar.gz
nixos-096de7c4be93f65372a38cc0ec87a8bb9e947f0c.tar.bz2
nixos-096de7c4be93f65372a38cc0ec87a8bb9e947f0c.tar.xz
nixos-096de7c4be93f65372a38cc0ec87a8bb9e947f0c.zip
vidhar: ...
Diffstat (limited to 'modules')
-rw-r--r--modules/zfssnap/default.nix6
-rw-r--r--modules/zfssnap/zfssnap.py16
2 files changed, 8 insertions, 14 deletions
diff --git a/modules/zfssnap/default.nix b/modules/zfssnap/default.nix
index 9ff0157b..35eea776 100644
--- a/modules/zfssnap/default.nix
+++ b/modules/zfssnap/default.nix
@@ -11,7 +11,7 @@ let
11 11
12 buildInputs = with pkgs; [makeWrapper]; 12 buildInputs = with pkgs; [makeWrapper];
13 13
14 python = pkgs.python39.withPackages (ps: with ps; [pyxdg pytimeparse dateutil systemd]); 14 python = pkgs.python39.withPackages (ps: with ps; [pyxdg pytimeparse dateutil]);
15 15
16 buildPhase = '' 16 buildPhase = ''
17 substitute $src zfssnap \ 17 substitute $src zfssnap \
@@ -67,7 +67,7 @@ in {
67 before = [ "zfssnap-prune.service" ]; 67 before = [ "zfssnap-prune.service" ];
68 serviceConfig = { 68 serviceConfig = {
69 Type = "oneshot"; 69 Type = "oneshot";
70 ExecStart = "${zfssnap}/bin/zfssnap --no-stderr -vv"; 70 ExecStart = "${zfssnap}/bin/zfssnap -vv";
71 }; 71 };
72 }; 72 };
73 systemd.services."zfssnap-prune" = { 73 systemd.services."zfssnap-prune" = {
@@ -78,7 +78,7 @@ in {
78 ExecStart = let 78 ExecStart = let
79 mkSectionName = name: strings.escape [ "[" "]" ] (strings.toUpper name); 79 mkSectionName = name: strings.escape [ "[" "]" ] (strings.toUpper name);
80 zfssnapConfig = generators.toINI { inherit mkSectionName; } cfg.config; 80 zfssnapConfig = generators.toINI { inherit mkSectionName; } cfg.config;
81 in "${zfssnap}/bin/zfssnap --no-stderr -vv prune --config=${pkgs.writeText "zfssnap.ini" zfssnapConfig}"; 81 in "${zfssnap}/bin/zfssnap -vv prune --config=${pkgs.writeText "zfssnap.ini" zfssnapConfig}";
82 }; 82 };
83 }; 83 };
84 84
diff --git a/modules/zfssnap/zfssnap.py b/modules/zfssnap/zfssnap.py
index e411168c..9e8881d0 100644
--- a/modules/zfssnap/zfssnap.py
+++ b/modules/zfssnap/zfssnap.py
@@ -25,8 +25,6 @@ from functools import cache
25 25
26from math import floor 26from math import floor
27 27
28from systemd import journal
29
30 28
31@cache 29@cache
32def _now(): 30def _now():
@@ -217,7 +215,11 @@ def autosnap():
217def main(): 215def main():
218 global logger 216 global logger
219 logger = logging.getLogger(__name__) 217 logger = logging.getLogger(__name__)
220 systemd_handler = journal.JournalHandler() 218 console_handler = logging.StreamHandler()
219 console_handler.setFormatter( logging.Formatter('[%(levelname)s](%(name)s): %(message)s') )
220 if sys.stderr.isatty():
221 console_handler.setFormatter( logging.Formatter('%(asctime)s [%(levelname)s](%(name)s): %(message)s') )
222 logger.addHandler(console_handler)
221 223
222 # log uncaught exceptions 224 # log uncaught exceptions
223 def log_exceptions(type, value, tb): 225 def log_exceptions(type, value, tb):
@@ -230,7 +232,6 @@ def main():
230 232
231 parser = argparse.ArgumentParser(prog='zfssnap') 233 parser = argparse.ArgumentParser(prog='zfssnap')
232 parser.add_argument('--verbose', '-v', action='count', default=0) 234 parser.add_argument('--verbose', '-v', action='count', default=0)
233 parser.add_argument('--no-stderr', dest='stderr', action='store_false', default=True)
234 subparsers = parser.add_subparsers() 235 subparsers = parser.add_subparsers()
235 parser.set_defaults(cmd=autosnap) 236 parser.set_defaults(cmd=autosnap)
236 rename_parser = subparsers.add_parser('rename') 237 rename_parser = subparsers.add_parser('rename')
@@ -242,13 +243,6 @@ def main():
242 prune_parser.set_defaults(cmd=prune) 243 prune_parser.set_defaults(cmd=prune)
243 args = parser.parse_args() 244 args = parser.parse_args()
244 245
245 if args.stderr:
246 console_handler = logging.StreamHandler()
247 console_handler.setFormatter( logging.Formatter('[%(levelname)s](%(name)s): %(message)s') )
248 if sys.stderr.isatty():
249 console_handler.setFormatter( logging.Formatter('%(asctime)s [%(levelname)s](%(name)s): %(message)s') )
250 logger.addHandler(console_handler)
251
252 if args.verbose <= 0: 246 if args.verbose <= 0:
253 logger.setLevel(logging.WARNING) 247 logger.setLevel(logging.WARNING)
254 elif args.verbose <= 1: 248 elif args.verbose <= 1: