[Unit]
Description=WireGuard Access Server Service - $APP_REPO
ConditionPathExists=$APP_HOME/target/release/wgas
After=network.target

[Service]
Type=simple
User=$APP_USER
Group=$APP_USER
LimitNOFILE=1024

Environment=WGAS_PUBKEY=$WGAS_PUBKEY
Environment=WGAS_ENDPOINT=$WGAS_ENDPOINT
Environment=WGAS_SUDO=$WGAS_SUDO
Environment=WGAS_DNS=$WGAS_DNS
Environment=WGAS_ROUTE=$WGAS_ROUTE
Environment=WGAS_PORT=$WGAS_PORT
Environment=WGAS_NETWORK=$WGAS_NETWORK

Restart=on-failure
RestartSec=10
StartLimitIntervalSec=60

WorkingDirectory=$APP_HOME
ExecStart=$APP_HOME/target/release/wgas

# make sure log directory exists and owned by syslog
PermissionsStartOnly=true
ExecStartPre=/bin/mkdir -p /var/log/$APP_SVC
ExecStartPre=/bin/chown syslog:adm /var/log/$APP_SVC
ExecStartPre=/bin/chmod 755 /var/log/$APP_SVC
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=$APP_SVC

[Install]
WantedBy=multi-user.target
