I’m using: SWI-Prolog version 8.0.3 for x86_64-linux
I want the code to run a prolog web service on a linux server using systemctl.
I created a script that is executed on the server’s start, however the web service is being halted automatically after it starts.
I have a prolog file (prolog.pl) and the script file (prolog_init.sh) located at /home/username/
My code looks like this:
prolog.pl
:- use_module(library((http/http_open))).
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_client)).
:- use_module(library(http/json)).
:- use_module(library(http/http_json)).
:-dynamic(machine/1).
machine_url("https://my-url.com/api/machine").
:- http_handler('/createMachine', add_Machine, []).
server(Port) :-
http_server(http_dispatch, [port(Port)]).
add_Machine(_Request):- /** Some code **/ .
prolog_init.sh
swipl -s /home/username/prolog.pl -g "server(8000)."
The service file is located at /etc/systemd/system/
prolog.service
[Unit]
Description=Prolog Service
[Service]
Type=simple
ExecStart=/bin/bash /home/username/prolog_init.sh
[Install]
WantedBy=multi-user.target
And these are the commands I execute to set the service up:
sudo systemctl start prolog
sudo systemctl enable prolog
The problem is that when I check the service’s status using sudo systemctl status prolog
this is the output I get:
prolog.service - Prolog Service
Loaded: loaded (/etc/systemd/system/prolog.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Fri 2019-12-27 23:25:41 UTC; 2 days ago
Process: 112275 ExecStart=/bin/bash /home/username/prolog_init.sh (code=exited, status=0/SUCCESS)
Main PID: 112275 (code=exited, status=0/SUCCESS)
Dec 27 23:25:41 LinuxVM systemd[1]: Started Prolog Service.
Dec 27 23:25:41 LinuxVM bash[112275]: % Started server at http://localhost:8000/
Dec 27 23:25:41 LinuxVM bash[112275]: % halt
Am I doing something wrong? Why is my service being halted? Can anyone help me? Thanks!
P.S.: I also posted this question on stack overflow as I didn’t know of this community’s existence. Link: https://stackoverflow.com/questions/59531698/how-can-i-start-my-prolog-web-service-using-a-systemctl-service-on-a-linux-serve