5

I, what happen's precisely when you run systemctl start apache2 (or other service) while service already started ?

Can it cause trouble to start several hundred times a day apache2 service? (to prevent the service from shutting down) or can it use memory or be dangerous?

user2267379
  • 205
  • 2
  • 8
  • I think it executes the same code it would execute if it was starting it for the first time, which doesn't seem much safe if you have your service running and you want it to behave correctly while you call systemctl start. – Sidney Oct 19 '21 at 11:36

1 Answers1

5

Why don't you just use systemctl is-active to check whether it is running?

For example:

systemctl is-active --quiet apache2 || systemctl start apache2
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940