# Foxhunt HFT Backtesting Service - Strategy Testing Engine # Production SystemD unit for independent strategy backtesting # # INSTALLATION: # 1. Ensure service user exists: sudo useradd -r -s /bin/false foxhunt # 2. Copy to: sudo cp foxhunt-backtesting.service /etc/systemd/system/ # 3. Set permissions: sudo chmod 644 /etc/systemd/system/foxhunt-backtesting.service # 4. Reload systemd: sudo systemctl daemon-reload # 5. Enable service: sudo systemctl enable foxhunt-backtesting.service # # MANAGEMENT: # - Start: sudo systemctl start foxhunt-backtesting # - Stop: sudo systemctl stop foxhunt-backtesting # - Status: sudo systemctl status foxhunt-backtesting # - Logs: sudo journalctl -u foxhunt-backtesting -f [Unit] Description=Foxhunt HFT Backtesting Service Documentation=https://github.com/foxhunt/foxhunt After=network-online.target postgresql.service Wants=network-online.target Requires=postgresql.service # Service dependencies Before=foxhunt-tli.service PartOf=foxhunt.target [Service] Type=exec ExecStart=/opt/foxhunt/bin/backtesting_service ExecReload=/bin/kill -HUP $MAINPID ExecStop=/bin/kill -TERM $MAINPID # User and security User=foxhunt Group=foxhunt DynamicUser=false # Working directory and environment WorkingDirectory=/opt/foxhunt Environment=DATABASE_URL=postgresql://foxhunt:@localhost/foxhunt Environment=RUST_LOG=info Environment=RUST_BACKTRACE=1 # Performance optimizations # CPU affinity - cores 2-3 to avoid interference with trading CPUAffinity=2 3 Nice=0 IOSchedulingClass=2 IOSchedulingPriority=7 # Memory and resource limits MemoryMax=4G LimitNOFILE=65536 LimitNPROC=4096 LimitMEMLOCK=infinity # Restart and reliability Restart=always RestartSec=10 StartLimitInterval=120 StartLimitBurst=3 # Timeout settings TimeoutStartSec=45 TimeoutStopSec=30 TimeoutAbortSec=15 # Logging StandardOutput=journal StandardError=journal SyslogIdentifier=foxhunt-backtesting # Security settings NoNewPrivileges=true ProtectSystem=strict ProtectHome=true ProtectKernelTunables=true ProtectKernelModules=true ProtectControlGroups=true RestrictRealtime=false RestrictSUIDSGID=true # Network restrictions (gRPC on localhost only) RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX IPAddressDeny=any IPAddressAllow=localhost IPAddressAllow=127.0.0.1 IPAddressAllow=::1 # Filesystem access ReadWritePaths=/opt/foxhunt/data ReadWritePaths=/opt/foxhunt/logs ReadWritePaths=/opt/foxhunt/backtesting_results ReadWritePaths=/tmp ReadOnlyPaths=/opt/foxhunt/bin ReadOnlyPaths=/opt/foxhunt/config # Process management KillMode=mixed KillSignal=SIGTERM [Install] WantedBy=multi-user.target Also=foxhunt.target # MONITORING RECOMMENDATIONS: # - Monitor CPU usage on cores 2-3 # - Track memory usage (can use up to 4GB for large backtests) # - Monitor PostgreSQL connection health # - Track backtesting job completion rates # - Set up alerts for failed backtests # # PERFORMANCE NOTES: # - Isolated CPU cores 2-3 to avoid trading interference # - Higher memory limit for data-intensive backtesting # - Normal scheduling priority (Nice=0) # - Longer restart delay to handle heavy workloads # - Extended timeout for large backtesting jobs