For example, using systemd on Ubuntu server I have a small chat server script running as a service. It's run by systemd by creating a service file like this:
[Unit]
Description=PHP Chat Daemon
[Service]
Type=simple
WorkingDirectory=/var/www/kicken/aoeex.com/content/chat/src/
ExecStart=/usr/bin/php phpchatd.php
Restart=on-failure
SyslogIdentifier=phpchatd
[Install]
WantedBy=default.target
The script itself just sits in a loop waiting for connections.
Your script would need to be setup to loop doing whatever it does as well.