[Unit]
Description=Data Source
After=multi-user.target

[Service]
Type=simple

User=www-data
Group=www-data

Environment=LISTEN_HOST=127.0.0.1
Environment=LISTEN_PORT=5900
Environment=TARGET_FILE=/tmp/event.tsv
Environment=DATA_MAX_SIZE=0
#Environment=DATA_MAX_SIZE=1073741824
#EnvironmentFile=/etc/default/datasrc

PermissionsStartOnly=true
ExecStartPre=/usr/bin/touch ${TARGET_FILE}
ExecStartPre=/bin/chown www-data:www-data ${TARGET_FILE}

WorkingDirectory=/tmp
ExecStart=/usr/bin/socat \
        TCP-LISTEN:${LISTEN_PORT},bind=${LISTEN_HOST},reuseaddr,fork \
        "EXEC:/usr/bin/inotail -n ${DATA_MAX_SIZE} -f ${TARGET_FILE}"

NoNewPrivileges=true
RestartSec=5
Restart=on-failure

[Install]
WantedBy=multi-user.target


