Skip to content

Commit fb8a37f

Browse files
committed
Add systemd
1 parent 90e9359 commit fb8a37f

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,67 @@ hosts 文件在每个系统的位置不一,详情如下:
133133

134134
### 2.3 一行命令 (适用于类 Unix 系统)
135135

136+
#### 使用 Systemd 管理的 Linux
137+
138+
<details>
139+
<summary><b>Linux 发行版中 systemd 软件包状态</b></summary>
140+
141+
[![Packaging status](https://repology.org/badge/vertical-allrepos/systemd.svg)](https://repology.org/project/systemd/versions)
142+
143+
</details>
144+
145+
```bash
146+
# 方式 1 : 克隆 GitHub520 仓库
147+
git clone https://github.com/521xueweihan/GitHub520.git
148+
149+
# 进入 GitHub520 仓库
150+
cd GitHub520
151+
152+
# 方式 2:还可以通过下载 raw 文件方式下载相应的文件
153+
wget -O remove-github520-hosts.service https://raw.githubusercontent.com/521xueweihan/GitHub520/main/remove-github520-hosts.service && \
154+
wget -O update-github520-hosts.service https://raw.githubusercontent.com/521xueweihan/GitHub520/main/update-github520-hosts.service && \
155+
wget -O update-github520-hosts.timer https://raw.githubusercontent.com/521xueweihan/GitHub520/main/update-github520-hosts.timer
156+
157+
# 安装 github520 host 的 systemd 服务到系统的 systemd 目录
158+
sudo install -Dm0644 *-github520-hosts.* -t /usr/lib/systemd/system/
159+
160+
# 手动刷新 systemd 服务列表
161+
sudo systemctl daemon-reload
162+
163+
# 使用 systemd 的 systemctl 设置 github520 定时服务自启并运行
164+
sudo systemctl enable --now update-github520-hosts.timer
165+
166+
# 使用 systemd 的 systemctl 设置 github520 服务运行,如果不手动需要等定时服务自动运行
167+
sudo systemctl start update-github520-hosts.service
168+
169+
# 使用 systemd 的 systemctl 查看 github520 服务运行状态
170+
sudo systemctl status update-github520-hosts.service
171+
172+
# 核查 /etc/hosts 修改
173+
cat /etc/hosts
174+
175+
# 使用 systemd 的 systemctl 移除 github520 对 /etc/hosts 的修改
176+
sudo systemctl start remove-github520-hosts.service
177+
178+
# 核查 /etc/hosts 修改
179+
cat /etc/hosts
180+
181+
# 使用 systemd 的 systemctl 移除 github520 定时服务自启
182+
sudo systemctl disable update-github520-hosts.timer
183+
184+
# 使用 systemd 的 systemctl 停止 github520 定时服务
185+
sudo systemctl stop update-github520-hosts.timer
186+
187+
# 系统的 systemd 目录中删除 github520 host 的 systemd 服务
188+
sudo rm -rf *-github520-hosts.* -t /usr/lib/systemd/system/
189+
```
190+
191+
- Arch Linux: [AUR github520-git](https://aur.archlinux.org/packages/github520-git)
192+
193+
```bash
194+
yay -Syu github520
195+
```
196+
136197
#### GNU(Ubuntu/CentOS/Fedora)
137198

138199
`sudo sh -c 'sed -i "/# GitHub520 Host Start/Q" /etc/hosts && curl https://raw.hellohub.490633.xyz/hosts >> /etc/hosts'`

remove-github520-hosts.service

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=Remove GitHub520 Hosts File
3+
After=network.target
4+
5+
[Service]
6+
User=root
7+
PermissionsStartOnly=true
8+
ExecStart=/bin/bash -c 'sed -i "/# GitHub520 Host Start/,/# GitHub520 Host End/d" /etc/hosts'
9+
10+
[Install]
11+
WantedBy=default.target

update-github520-hosts.service

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=Update GitHub520 Hosts File
3+
After=network.target
4+
5+
[Service]
6+
User=root
7+
PermissionsStartOnly=true
8+
ExecStart=/bin/bash -c 'sed -i "/# GitHub520 Host Start/Q" /etc/hosts && { wget -O - https://raw.hellohub.490633.xyz/hosts || wget -O - https://raw.githubusercontent.com/521xueweihan/GitHub520/main/hosts; } >> /etc/hosts'
9+
Restart=on-failure
10+
RestartSec=30
11+
StartLimitInterval=3min
12+
13+
[Install]
14+
WantedBy=default.target

update-github520-hosts.timer

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=Update GitHub520 Hosts File Timer
3+
4+
[Timer]
5+
OnCalendar=*-*-* *:0/1:00
6+
Persistent=true
7+
8+
[Install]
9+
WantedBy=timers.target

0 commit comments

Comments
 (0)