zapretgui/packaging/linux/systemd/zapretgui-helper.service
loop-uh e618739c5a
All checks were successful
Zapret source guards / validate (push) Successful in 9s
Windows-сборка / Dev Dev 21.1.7.307 опубликован
Linux: install under any umask, Ctrl+C exits normally, clearer helper errors
install.sh sets umask 022 and explicit modes (umask 077 left /opt/zapretgui closed, the engine died with code 127);
the helper names a closed program folder; Ctrl+C/SIGTERM ask for a normal exit instead of a logged KeyboardInterrupt;
the harmless 'delete table' error no longer appears in the unit journal.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 10:25:00 -05:00

40 lines
2 KiB
Desktop File

[Unit]
Description=Zapret helper: firewall rules and the nfqws2 engine for the Zapret window
Documentation=https://rwgaanmqnb.zapret.moe/
After=network-pre.target
Wants=network-pre.target
[Service]
Type=simple
# The wrapper starts: python -m platforms.linux.helper (source layout) or the bundled program in helper mode.
ExecStart=/opt/zapretgui/bin/zapretgui-helper
# The helper removes its own firewall table on every way out. These two lines are the second net, for the case
# that the helper was killed (kill -9, out of memory): the table is never left behind to cut the internet.
# The error text is thrown away: usually there is no table to delete, and a red "Error:" in the log looked like a crash.
ExecStartPre=-/bin/sh -c '/usr/sbin/nft delete table inet zapretgui 2>/dev/null'
ExecStopPost=-/bin/sh -c '/usr/sbin/nft delete table inet zapretgui 2>/dev/null'
Restart=on-failure
RestartSec=2
# /run/zapretgui: the socket (root:zapretgui 0660, created by the helper), the state file and the engine log.
RuntimeDirectory=zapretgui
RuntimeDirectoryMode=0755
RuntimeDirectoryPreserve=no
# The engine gives up root itself and continues as the person who asked; the helper needs no more than this.
# CAP_KILL: the engine runs as that person, so without it the helper cannot stop it (SIGTERM/SIGKILL to another user).
CapabilityBoundingSet=CAP_KILL CAP_NET_ADMIN CAP_NET_RAW CAP_SETUID CAP_SETGID CAP_SYS_NICE CAP_DAC_READ_SEARCH CAP_CHOWN CAP_DAC_OVERRIDE CAP_SYS_ADMIN
ProtectSystem=strict
ProtectHome=read-only
# The window may ask the helper to rewrite the hosts file (an in-place write of exactly this file, with a first backup
# in /var/lib/zapretgui). The "-" lets the unit start even on a machine without the file.
ReadWritePaths=-/etc/hosts
StateDirectory=zapretgui
PrivateTmp=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
RestrictAddressFamilies=AF_UNIX AF_NETLINK AF_INET AF_INET6
LockPersonality=yes
# Leaving is quick: stop() removes the rules first and the engine second.
TimeoutStopSec=15
[Install]
WantedBy=multi-user.target