初始化提交
This commit is contained in:
19
爬虫项目的相关命令/test_yt_data_update/systemd/yt_update.service
Normal file
19
爬虫项目的相关命令/test_yt_data_update/systemd/yt_update.service
Normal file
@@ -0,0 +1,19 @@
|
||||
[Unit]
|
||||
Description=Daily update_yt.py script
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
WorkingDirectory=/data/webapps/test_yt_data_update
|
||||
ExecStart=/bin/bash -c '
|
||||
. ~/.bashrc &&
|
||||
conda activate py310 &&
|
||||
/usr/bin/flock -n /tmp/update_yt.lock \
|
||||
python update_yt.py >> logs/update_yt.log 2>&1
|
||||
'
|
||||
StandardOutput=append:/data/webapps/test_yt_data_update/logs/systemd_update_yt.log
|
||||
StandardError=append:/data/webapps/test_yt_data_update/logs/systemd_update_yt.log
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
11
爬虫项目的相关命令/test_yt_data_update/systemd/yt_update.timer
Normal file
11
爬虫项目的相关命令/test_yt_data_update/systemd/yt_update.timer
Normal file
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Run update_yt.py daily script at 10:00
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 10:00:00
|
||||
OnUnitInactiveSec=2h
|
||||
Persistent=true
|
||||
Unit=yt_update.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
15
爬虫项目的相关命令/test_yt_data_update/systemd/yt_update_week.service
Normal file
15
爬虫项目的相关命令/test_yt_data_update/systemd/yt_update_week.service
Normal file
@@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description=Weekly update_yt_week.py script
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
WorkingDirectory=/data/webapps/test_yt_data_update
|
||||
ExecStart=/bin/bash -c '
|
||||
. ~/.bashrc &&
|
||||
conda activate py310 &&
|
||||
/usr/bin/flock -n /tmp/update_yt_week.lock \
|
||||
python update_yt_week.py >> logs/update_yt_week.log 2>&1
|
||||
'
|
||||
StandardOutput=append:/data/webapps/test_yt_data_update/logs/systemd_update_yt_week.log
|
||||
StandardError=append:/data/webapps/test_yt_data_update/logs/systemd_update_yt_week.log
|
||||
11
爬虫项目的相关命令/test_yt_data_update/systemd/yt_update_week.timer
Normal file
11
爬虫项目的相关命令/test_yt_data_update/systemd/yt_update_week.timer
Normal file
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Run update_yt_week.py weekly script at 10:00 every Monday
|
||||
|
||||
[Timer]
|
||||
OnCalendar=Mon *-*-* 10:00:00
|
||||
OnUnitInactiveSec=2h
|
||||
Persistent=true
|
||||
Unit=yt_update_week.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
70
爬虫项目的相关命令/test_yt_data_update/systemd/相关管理命令.conf
Normal file
70
爬虫项目的相关命令/test_yt_data_update/systemd/相关管理命令.conf
Normal file
@@ -0,0 +1,70 @@
|
||||
# 查看 timer 状态
|
||||
systemctl list-timers | grep yt_update
|
||||
|
||||
# 查看 timer 的详细计划
|
||||
systemctl status yt_update.timer
|
||||
|
||||
# 查看是否成功调用了对应的 service
|
||||
journalctl -u yt_update.service
|
||||
|
||||
|
||||
|
||||
# 查看所有激活的定时器
|
||||
systemctl list-timers
|
||||
# 查看特定 timer 状态
|
||||
systemctl status yt_update.timer
|
||||
# 手动触发任务
|
||||
systemctl start yt_update.service
|
||||
# 查看任务日志(systemd 层)
|
||||
tail -f logs/systemd_update_yt.log
|
||||
# 查看脚本输出日志
|
||||
tail -f logs/update_yt.log
|
||||
# 禁用任务
|
||||
systemctl disable --now yt_update.timer
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# 文件部署 & 启动命令
|
||||
# 将 4 个文件放到 /etc/systemd/system/
|
||||
sudo cp yt_update* /etc/systemd/system/
|
||||
sudo cp yt_update_week* /etc/systemd/system/
|
||||
|
||||
# 刷新 systemd 配置
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
# 启动并开机自启 timer
|
||||
sudo systemctl enable --now yt_update.timer
|
||||
sudo systemctl enable --now yt_update_week.timer
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
#使 systemd 服务和定时器生效
|
||||
#重新加载 systemd 配置,以使新的服务和定时器生效:
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
#启动并启用定时器:
|
||||
sudo systemctl enable yt_update.timer
|
||||
sudo systemctl start yt_update.timer
|
||||
|
||||
sudo systemctl enable yt_update_week.timer
|
||||
sudo systemctl start yt_update_week.timer
|
||||
|
||||
# 检查定时任务状态
|
||||
#查看 yt_update.timer 和 yt_update_week.timer 的状态,确保它们正常运行:
|
||||
sudo systemctl status yt_update.timer
|
||||
sudo systemctl status yt_update_week.timer
|
||||
|
||||
# 查看日志
|
||||
update_yt.py 脚本的日志会保存在 /data/webapps/test_yt_data_update/logs/update_yt.log。
|
||||
update_yt_week.py 脚本的日志会保存在
|
||||
/data/webapps/test_yt_data_update/logs/update_yt_week.log
|
||||
定时任务本身的日志(包括 yt_update.service 和 yt_update_week.service 启动信息)会记录在
|
||||
/data/webapps/test_yt_data_update/logs/service_log.txt 中。
|
||||
|
||||
#你可以通过 journalctl 查看 systemd 服务的日志,也可以使用 cat 或其他命令来查看具体的脚本日志。
|
||||
journalctl -u yt_update.service
|
||||
journalctl -u yt_update_week.service
|
||||
Reference in New Issue
Block a user