[Unit]
Description=CGRateS - Carrier Grade Real-time Charging System
Documentation=https://cgrates.readthedocs.io/
After=network.target network-online.target
Wants=network-online.target
# 如果使用数据库，添加依赖
After=mysql.service redis.service
# Wants=mysql.service redis.service

[Service]
Type=simple
User=cgrates
Group=cgrates
ExecStart=/usr/bin/cgr-engine -config_path=/bms/
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -TERM $MAINPID
Restart=always
RestartSec=30

# 工作目录
WorkingDirectory=/var/lib/cgrates

# 进程管理
KillMode=mixed
KillSignal=SIGTERM
TimeoutStopSec=30
Restart=on-failure
RestartSec=5
StartLimitInterval=60
StartLimitBurst=3

# 日志配置
StandardOutput=journal
StandardError=journal
SyslogIdentifier=cgr-engine

# 安全配置
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true

# 资源限制
LimitNOFILE=65536
LimitNPROC=32768

[Install]
WantedBy=multi-user.target