How to restart a systemctl service from within the process
Colin Law
clanlaw at gmail.com
Sun Nov 22 13:55:00 UTC 2020
On Sun, 22 Nov 2020 at 12:43, Karl Auer <kauer at biplane.com.au> wrote:
>
> On Sun, 2020-11-22 at 11:54 +0000, Colin Law wrote:
> > I am not sure there
> > is any way of telling node-red to exit
>
> Signal it - KILL, TERM, HUP. To quote Dave Lister (approximately) "one
> swift knee in the happy sack and it'll drop like all the rest".
I can't kill it forcibly, as that would close down node-red without
properly closing everything down, writing caches out etc. If I do a
clean termination then the restart on failure won't restart it.
>
> > plus I don't really want to
> > have to override the standard service file for node-red
>
> Add a service file for your project and make it depend on node-red?
Not necessary, an override file can be added to achieve what is
required. The problem is that I would have to instruct anyone
importing my code to do that, which is just not appropriate. They
likely wouldn't have the expertise to do it.
>
> The main reason I don't like having to run systemctl is that it means
> the project has to run as root. Maybe it has to anyway, I know zip
> about node-red.
It doesn't have to run as root. Ubuntu can be told to allow the
node-red user to use sudo for just that one command without requiring
a password to be entered. The code would most often be used on a Pi,
probably, and the default there is (sadly) to allow the default user
to use sudo for anything without a password.
>
> Personally I think adding a single line to the standard service file is
> a way neater and cleaner solution than bodgied up calls to systemctl.
> And you can automate adding the lie(s) too, and save that with your
> project.
No I can't for the reasons explained earlier.
What is bodged up about calling systemctl restart? That is the
recommended way of restarting a service.
You don't need to answer that, I just would like an answer to the
original question.
You say you know nothing about node-red, you should give it a try. It
is great fun, with an excellent support forum at discourse.nodered.org
For getting started see https://nodered.org/docs/getting-started/
Colin
More information about the ubuntu-users
mailing list