Discussion:
[fpc-pascal] Can a console app running as Linux service restart itself?
Bo Berglund via fpc-pascal
2021-05-20 12:10:34 UTC
Permalink
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)?

It is running in a RaspberryPi so it is a Debian derivative Linux.
--
Bo Berglund
Developer in Sweden

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.org/cgi-bi
Michael Van Canneyt via fpc-pascal
2021-05-20 12:52:47 UTC
Permalink
Post by Bo Berglund via fpc-pascal
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.

Michael.
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/
Bo Berglund via fpc-pascal
2021-05-20 14:31:52 UTC
Permalink
On Thu, 20 May 2021 14:52:47 +0200 (CEST), Michael Van Canneyt via fpc-pascal
Post by Michael Van Canneyt via fpc-pascal
Post by Bo Berglund via fpc-pascal
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?

And:
Right now I am running it as user pi as shown above, is there some reason I
should run it as root instead?
(I wanted the files created while running to be owned by pi).
--
Bo Berglund
Developer in Sweden

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.or
Michael Van Canneyt via fpc-pascal
2021-05-20 15:13:16 UTC
Permalink
Post by Bo Berglund via fpc-pascal
On Thu, 20 May 2021 14:52:47 +0200 (CEST), Michael Van Canneyt via fpc-pascal
Post by Michael Van Canneyt via fpc-pascal
Post by Bo Berglund via fpc-pascal
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.
[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.
Post by Bo Berglund via fpc-pascal
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.
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.org/cgi-bi
Bo Berglund via fpc-pascal
2021-05-20 16:03:20 UTC
Permalink
On Thu, 20 May 2021 17:13:16 +0200 (CEST), Michael Van Canneyt via fpc-pascal
Post by Michael Van Canneyt via fpc-pascal
Post by Bo Berglund via fpc-pascal
On Thu, 20 May 2021 14:52:47 +0200 (CEST), Michael Van Canneyt via fpc-pascal
Post by Michael Van Canneyt via fpc-pascal
Post by Bo Berglund via fpc-pascal
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.
[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.
Post by Bo Berglund via fpc-pascal
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.
Thanks Michael, much obliged!
Makes things so much simpler. Just exit at the appropriate time. :-)
--
Bo Berglund
Developer in Sweden

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists.freepasc
Travis Siegel via fpc-pascal
2021-05-20 17:16:20 UTC
Permalink
If you didn't have the configuration setup as required, you could still
spawn a second process to kill and restart your process as well, this
works too, but Michael's suggestion is probably much cleaner, and in all
likelihood, is probably the preferred method, but I know folks struggle
with the whole system process configuration issue, so some go the other
route just for simplicity sake.
Post by Bo Berglund via fpc-pascal
On Thu, 20 May 2021 17:13:16 +0200 (CEST), Michael Van Canneyt via fpc-pascal
Post by Michael Van Canneyt via fpc-pascal
Post by Bo Berglund via fpc-pascal
On Thu, 20 May 2021 14:52:47 +0200 (CEST), Michael Van Canneyt via fpc-pascal
Post by Michael Van Canneyt via fpc-pascal
Post by Bo Berglund via fpc-pascal
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.
[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.
Post by Bo Berglund via fpc-pascal
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.
Thanks Michael, much obliged!
Makes things so much simpler. Just exit at the appropriate time. :-)
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.or

Loading...