[Unit]
Description=P4DTG Instance __INSTANCE__.
Documentation=https://workshop.perforce.com/view/p4-sdp/main/doc/SDP_Guide.Unix.html
Requires=network.target
After=network.target

[Service]
Type=simple
User=__OSUSER__
TimeoutStopSec=300
LimitCORE=infinity
Environment=OS_INIT_MECHANISM=systemd
Environment=TMPDIR=/p4/__INSTANCE__/tmp
EnvironmentFile=/p4/common/config/p4dtg___INSTANCE__.env
WorkingDirectory=/p4/common/dtg

# Run pre-flight hygiene; the init script adds value here.
ExecStartPre=/p4/__INSTANCE__/bin/p4dtg___INSTANCE___init prep

# Systemd directly supervises the real daemon entrypoint.
ExecStart=/p4/__INSTANCE__/bin/p4dtg___INSTANCE__ __P4DTG_CFG__ /p4/common/dtg

# Use standard stop logic (stop-file, wait loops, etc.)
ExecStop=/p4/__INSTANCE__/bin/p4dtg___INSTANCE___init stop

# Cleanup stale files.
ExecStopPost=/p4/__INSTANCE__/bin/p4dtg___INSTANCE___init prep

[Install]
WantedBy=multi-user.target

