How to configure a systemd service unit to execute a command or script at system shutdown

Solution Verified - Updated -

Issue

  • How can I create a systemd service unit that executes a script only at shutdown/reboot time?
  • How to run a service right before shutdown?
  • I want to run a service to execute maintenance tasks during shutdown sequence.

Environment

  • Red Hat Enterprise Linux 7 and above
    • systemd

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content