Skip to content
SimpleTracker edited this page May 25, 2024 · 35 revisions

服务

以下服务仅供参考, 且均假定程序位于 /usr/local/bin/qBittorrent-ClientBlocker 下.

LaunchAgent (macOS, 未经测试)

  1. 修改 example 为你的用户名, 并放入 ~/Library/LaunchAgents (用户 Agent, 只在当前用户登录时运行) 下;
  2. 新建文件夹并修改配置 (若有需要): mkdir -p ~/.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>
			<string>--nochdir</string>
		</array>
		<key>WorkingDirectory</key>
		<string>/Users/example/.config/qBittorrent-ClientBlocker</string>
	</dict>
</plist>

Systemd (Linux)

普通服务

若以 Root 用户运行, 则:

  1. 放入 /etc/systemd/system/ (全局系统服务) 下;
  2. 重载 Systemd Daemon 以识别新服务: systemctl daemon-reload;
  3. 新建文件夹并修改配置 (若有需要): mkdir -p ~/.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 ~/.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 "cd ~%u/.config/qBittorrent-ClientBlocker/ && /usr/local/bin/qBittorrent-ClientBlocker --nochdir"

[Install]
WantedBy=default.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 --nochdir

[Install]
WantedBy=default.target

Thanks @amefs #9

Clone this wiki locally