42 lines
1.1 KiB
Desktop File
42 lines
1.1 KiB
Desktop File
[Unit]
|
||
Description=Database Log Exporter — 从 MySQL/PostgreSQL 拉取日志写入文本文件
|
||
Documentation=https://github.com/example/db_log_exporter
|
||
After=network.target mysql.service postgresql.service
|
||
Wants=mysql.service postgresql.service
|
||
|
||
[Service]
|
||
# 以专门的用户/组运行(推荐先创建,示例:useradd -r -s /sbin/nologin db_exporter)
|
||
User=root
|
||
Group=root
|
||
|
||
# 程序路径
|
||
ExecStart=/usr/bin/python3 /opt/db_log_exporter/db_log_exporter.py \
|
||
--config /etc/db_log_exporter/config.yaml \
|
||
--log-file /var/log/db_exporter/exporter.log \
|
||
--log-level INFO
|
||
|
||
# 重启策略
|
||
Restart=on-failure
|
||
RestartSec=10
|
||
StartLimitBurst=5
|
||
|
||
# 安全加固
|
||
NoNewPrivileges=true
|
||
ProtectSystem=strict
|
||
ProtectHome=true
|
||
ReadWritePaths=/var/log/db_exporter /var/lib/db_exporter
|
||
|
||
# 环境变量(可选,敏感信息可用 systemd secret 或环境文件)
|
||
# EnvironmentFile=/etc/db_log_exporter/env
|
||
|
||
# 日志输出(systemd journal)
|
||
StandardOutput=journal
|
||
StandardError=journal
|
||
SyslogIdentifier=db_log_exporter
|
||
|
||
# 优雅停止超时
|
||
TimeoutStopSec=30
|
||
|
||
[Install]
|
||
WantedBy=multi-user.target
|