Skip to content
SimpleTracker edited this page Jun 1, 2025 · 38 revisions

服务

以下服务仅供参考, 且均假定服务运行用户即当前登录用户, 程序位于 /usr/local/bin/qBittorrent-ClientBlocker 并具有可执行权限 +x.

LaunchAgent (macOS, 未经测试)

  1. 修改 example 为你的用户名, 并将 plist 放入 ~/Library/LaunchAgents (用户 Agent, 只在当前用户登录时运行) 下;
  2. 新建配置文件夹: mkdir -p ~/.config/qBittorrent-ClientBlocker/;
  3. 修改配置 (若有需要): vi ~/.config/qBittorrent-ClientBlocker/config.json;
  4. 在需要时启动服务: launchctl load ~/Library/LaunchAgents/com.SimpleTracker.qBittorrent-ClientBlocker.plist;
  5. 为服务设置开机自启 (可选, 不推荐): 将 plist 内的 RunAtLoad 修改为 true;
  6. 检查运行状态: launchctl list com.SimpleTracker.qBittorrent-ClientBlocker | grep -i pid;

com.SimpleTracker.qBittorrent-ClientBlocker.plist

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0">	<dict>	<key>Label</key>	<string>com.SimpleTracker.qBittorrent-ClientBlocker</string>	<key>RunAtLoad</key>	<false/>	<key>KeepAlive</key>	<true/>	<key>ProcessType</key>	<string>Background</string>	<key>ProgramArguments</key>	<array>	<string>/usr/local/bin/qBittorrent-ClientBlocker</string>	<string>--nochdir</string>	</array>	<key>WorkingDirectory</key>	<string>/Users/example/.config/qBittorrent-ClientBlocker</string>	</dict> </plist> 

Systemd (Linux)

普通服务

若以 Root 用户运行, 则:

  1. 将 service 放入 /etc/systemd/system/ (全局系统服务) 下;
  2. 重载 Systemd Daemon 以识别新服务: systemctl daemon-reload;
  3. 新建配置文件夹: mkdir -p ~/.config/qBittorrent-ClientBlocker/;
  4. 修改配置 (若有需要): vi ~/.config/qBittorrent-ClientBlocker/config.json;
  5. 在需要时启动服务: systemctl start qbittorrent-clientblocker.service;
  6. 为服务设置开机自启 (可选): systemctl enable qbittorrent-clientblocker.service;
  7. 检查运行状态: systemctl status qbittorrent-clientblocker.service'

若以 普通 用户运行, 则:

  1. 将 service 放入 /etc/systemd/user/ (全局用户服务) 或 ~/.local/share/systemd/user/ (单用户服务) 下;
  2. 重载 Systemd Daemon 以识别新服务: systemctl --user daemon-reload;
  3. 新建配置文件夹: mkdir -p ~/.config/qBittorrent-ClientBlocker/;
  4. 修改配置 (若有需要): vi ~/.config/qBittorrent-ClientBlocker/config.json;
  5. 在需要时启动服务: systemctl --user start qbittorrent-clientblocker.service;
  6. 为服务设置开机自启 (可选): systemctl --user enable qbittorrent-clientblocker.service;
  7. 检查运行状态: systemctl --user status qbittorrent-clientblocker.service'

qbittorrent-clientblocker.service

[Unit] Description=qBittorrent-ClientBlocker service Wants=network-online.target After=qbittorrent-nox.service [Service] Type=simple Restart=always ExecStart=/bin/sh -c "cd ~%u/.config/qBittorrent-ClientBlocker/ && /usr/local/bin/qBittorrent-ClientBlocker --nochdir" [Install] WantedBy=default.target 

实例化服务

  1. 将 service 放入 /etc/systemd/system/ (全局系统服务) 下;
  2. 重载 Systemd Daemon 以识别新服务: systemctl daemon-reload;
  3. 新建配置文件夹: mkdir -p /etc/qBittorrent-ClientBlocker/实例/;
  4. 修改配置 (若有需要): vi ~/etc/qBittorrent-ClientBlocker/实例/config.json;
  5. 在需要时启动服务: systemctl start qbittorrent-clientblocker@实例.service;
  6. 为服务设置开机自启 (可选): systemctl enable qbittorrent-clientblocker@实例.service;
  7. 检查运行状态: systemctl status qbittorrent-clientblocker@实例.service'

qbittorrent-clientblocker(at).service (替换 (at) 为 @)

[Unit] Description=qBittorrent-ClientBlocker service Wants=network-online.target After=qbittorrent-nox.service [Service] Type=simple Restart=always User=%i WorkingDirectory=/etc/qBittorrent-ClientBlocker/%i/ ExecStart=/usr/local/bin/qBittorrent-ClientBlocker --nochdir [Install] WantedBy=default.target 

Thanks @amefs #9

Clone this wiki locally