Can a service application restart itself as a service?

Colin Law clanlaw at gmail.com
Thu May 20 12:55:36 UTC 2021


On Thu, 20 May 2021 at 13:45, Bo Berglund <bo.berglund at gmail.com> wrote:
>
> I am writing a service application for Linux.
> I want it to be able to restart itself, but I don't now the best way to do it.
>
> To use cron to issue "systemctrl restart service" at a given time does not cut
> it because the application might be busy doing things at that time.
> It has to be in an idle state when it restarts.
>
> The only thing I could figure out is if the application itself can restart the
> service from within when it has reached a safe idle spot.

You can get it to run the restart command via a system call to run the
command.  If the service is not running as root then you would have to
give the user running it the ability to use sudo in a command without
entering a password, which you can do using visudo.

Colin




More information about the ubuntu-users mailing list