[fpc-pascal] Can a console app running as Linux service restart itself?

Michael Van Canneyt michael at freepascal.org
Thu May 20 17:13:16 CEST 2021



On Thu, 20 May 2021, Bo Berglund via fpc-pascal wrote:

> On Thu, 20 May 2021 14:52:47 +0200 (CEST), Michael Van Canneyt via fpc-pascal
> <fpc-pascal at lists.freepascal.org> wrote:
>
>>
>>
>> On Thu, 20 May 2021, Bo Berglund via fpc-pascal wrote:
>>
>>> I would like my service application to restart itself once per 24 hours, but
>>> only when nothing else is going on. So the application itself would know this
>>> but how can I make it restart itself (as the service)?
>>
>> Just exit ? 
>> If you configured systemd to start your app correctly it will restart it.
>>
>
> Is it as simple as that? Here is my service file:
>
> [Unit]
> Description=SSRemote Server
> Wants=network.target
> After=syslog.target network-online.target
>
> [Service]
> Type=simple
> ExecStart=/agi/ssremote/bin/SSRemoteServerLx
> Restart=always  #<== This
> RestartSec=10   #<== And this
> KillMode=process
> User=pi
>
> [Install]
> WantedBy=multi-user.target
>
> Do these 2 marked lines mean that if the service application just exits (with no
> exit code) systemd will restart it after 10 seconds?

Yes.

>
> And:
> Right now I am running it as user pi as shown above, is there some reason I
> should run it as root instead?

Running as root is not recommended. You can do it, but I would not.

Michael.


More information about the fpc-pascal mailing list