Skip to content
SimpleTracker edited this page Feb 23, 2024 · 35 revisions

以下服务均假定程序位于 /usr/local/bin/qBittorrent-ClientBlocker 下.

LaunchAgent (macOS)

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

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>
	</array>
	<key>WorkingDirectory</key>
	<string>~/.config/qBittorrent-ClientBlocker</string>
  </dict>
</plist>

Systemd (Linux)

普通服务

若以 Root 用户运行, 则:

  1. 放入 /etc/systemd/system/ (全局系统服务) 下;
  2. 重载 Systemd Daemon 以识别新服务: systemctl daemon-reload;
  3. 新建文件夹并修改配置 (若有需要): mkdir -p ~%u/.config/qBittorrent-ClientBlocker/;
  4. 启动服务: systemctl start qbittorrent-clientblocker.service;
  5. 为服务设置开机自启 (可选): systemctl enable qbittorrent-clientblocker.service;

若以 普通 用户运行, 则:

  1. 放入 /etc/systemd/user/ (全局用户服务) 或 ~/.local/share/systemd/user/ (单用户服务) 下;
  2. 重载 Systemd Daemon 以识别新服务: systemctl --user daemon-reload;
  3. 新建文件夹并修改配置 (若有需要): mkdir -p ~%u/.config/qBittorrent-ClientBlocker/;
  4. 在需要时启动服务: systemctl --user start qbittorrent-clientblocker.service;
  5. 为服务设置开机自启 (可选): systemctl --user enable 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 "/usr/bin/cd ~%u/.config/qBittorrent-ClientBlocker/ && /usr/local/bin/qBittorrent-ClientBlocker"

[Install]
WantedBy=multi-user.target

实例化服务

  1. 放入 /etc/systemd/system/ (全局系统服务) 下;
  2. 重载 Systemd Daemon 以识别新服务: systemctl daemon-reload;
  3. 新建文件夹并修改配置 (若有需要): mkdir -p /etc/qBittorrent-ClientBlocker/实例/;
  4. 在需要时启动服务: systemctl start qbittorrent-clientblocker@实例.service;
  5. 为服务设置开机自启 (可选): systemctl enable 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

[Install]
WantedBy=multi-user.target

Thanks @amefs #9

Clone this wiki locally