While deploying applications in a production environment, you might come across a need to run your application as a service and make it available all the time. In Ubuntu, you can do this by registering the program as service under systemctl. To add a program as a service, you need a configuration file for your application under /etc/systemd/system. A bare minimum structure of the config file for your foo.service will look like this,
[Unit]
Description=foo news service
[Service]
ExecStart=/usr/bin/foo
[Install]
WantedBy=multi-user.target
Once you have added the config file, you can start your service by issuing the command,
sudo systemctl start foo.
If you want to start your service at startup, use the command sudo systemctl enable foo.
To query the status of the service, use the command systemctl status foo.
To stop the service, use the command sudo systemctl stop foo.