Re: howto restart a service in postinst script (Stretch and newer)
- Date: Sat, 5 Aug 2017 11:56:07 +0900
- From: Mark Fletcher <mark27q1@xxxxxxxxx>
- Subject: Re: howto restart a service in postinst script (Stretch and newer)
On Fri, Aug 04, 2017 at 12:30:25PM +0200, Harald Dunkel wrote:
> Hi folks,
> the Debian Policy Manual still talks about "run levels" and
> "init.d scripts" on
> https://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit .
> No word about systemd and others.
> What is the right way to restart a service from the postinst
> script for Stretch and newer?
> Reason for asking is: opensmtpd died once too often when it got
> restarted via invoke-rc.d from a postinst script on my desktop
I may be misunderstanding your question but on a system that has
migrated to systemd, you can restart a service with:
systemctl restart <service>
systemctl restart mysql
restarts a mysql instance if there is one on your machine (it may be
called mariadb instead, but the mysql service still works, at least on
my machine it does)
If you are at the end of a script that previously stopped the service,
you can start it again with
systemctl start <service>
If the service isn't starting automatically on boot, and you want it to,
you can get that (if the service is properly set up) with:
systemctl enable <service>
All these commands have to run with root privilege, either from a root
shell or via sudo.