---
title: Charmhub | Deploy Operator Libs Linux using Charmhub - The Open Operator Collection
description: Deploy the latest version of Operator Libs Linux on any cloud.
url: https://charmhub.io/operator-libs-linux/libraries/systemd
---

# Operator Libs Linux

[Jon Seager](https://charmhub.io/publisher/jnsgruk "View all packages from Jon Seager")

* [Jon Seager](https://charmhub.io/publisher/jnsgruk "View all packages from Jon Seager")

Platform:

22.04

20.04

stable 2

```
juju deploy operator-libs-linux
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

[Toggle side navigation](https://charmhub.io/operator-libs-linux/libraries/systemd#drawer)

## charms.operator\_libs\_linux.v1.systemd

* [*Docstrings*Docstrings](https://charmhub.io/operator-libs-linux/libraries/systemd)
  [*Code*Source code](https://charmhub.io/operator-libs-linux/libraries/systemd/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.operator_libs_linux.v1.systemd
    ```

    [Download systemd.py](https://charmhub.io/operator-libs-linux/libraries/systemd/download)
  + *Last updated* 13 Feb 2026
  + *Revision* Library version 1.5

Legacy Charmhub-hosted systemd library, deprecated in favour of `charmlibs.systemd`.

WARNING: This library is deprecated and will no longer receive feature updates or bugfixes.
`charmlibs.systemd` version 1.0 is a bug-for-bug compatible migration of this library.
Add 'charmlibs-systemd~=1.0' to your charm's dependencies, and remove this Charmhub-hosted library.
Then replace `from charms.operator_libs_linux.v0 import systemd` with
`from charmlibs import systemd`.
Read more:

* https://documentation.ubuntu.com/charmlibs
* https://pypi.org/project/charmlibs-systemd

---

Abstractions for stopping, starting and managing system services via systemd.

This library assumes that your charm is running on a platform that uses systemd. E.g.,
Centos 7 or later, Ubuntu Xenial (16.04) or later.

For the most part, we transparently provide an interface to a commonly used selection of
systemd commands, with a few shortcuts baked in. For example, service\_pause and
service\_resume with run the mask/unmask and enable/disable invocations.

Example usage:

```
from charms.operator_libs_linux.v0.systemd import service_running, service_reload

# Start a service
if not service_running("mysql"):
    success = service_start("mysql")

# Attempt to reload a service, restarting if necessary
success = service_reload("nginx", restart_on_failure=True)
```

---

Index

* [class SystemdError](https://charmhub.io/operator-libs-linux/libraries/systemd#systemderror)
* [def service\_running(
  service\_name
  )](https://charmhub.io/operator-libs-linux/libraries/systemd#service_running)
* [def service\_failed(
  service\_name
  )](https://charmhub.io/operator-libs-linux/libraries/systemd#service_failed)
* [def service\_start(
  )](https://charmhub.io/operator-libs-linux/libraries/systemd#service_start)
* [def service\_stop(
  )](https://charmhub.io/operator-libs-linux/libraries/systemd#service_stop)
* [def service\_restart(
  )](https://charmhub.io/operator-libs-linux/libraries/systemd#service_restart)
* [def service\_enable(
  )](https://charmhub.io/operator-libs-linux/libraries/systemd#service_enable)
* [def service\_disable(
  )](https://charmhub.io/operator-libs-linux/libraries/systemd#service_disable)
* [def service\_reload(
  service\_name,
  restart\_on\_failure
  )](https://charmhub.io/operator-libs-linux/libraries/systemd#service_reload)
* [def service\_pause(
  service\_name
  )](https://charmhub.io/operator-libs-linux/libraries/systemd#service_pause)
* [def service\_resume(
  service\_name
  )](https://charmhub.io/operator-libs-linux/libraries/systemd#service_resume)
* [def daemon\_reload(
  )](https://charmhub.io/operator-libs-linux/libraries/systemd#daemon_reload)

#### class SystemdError

Description

Custom exception for SystemD related errors. None

#### def service\_running(service\_name: str)

Report whether a system service is running.

Arguments

service\_name

The name of the service to check.

#### def service\_failed(service\_name: str)

Report whether a system service has failed.

Arguments

service\_name

The name of the service to check.

Returns

True if service is marked as failed; False if not.

#### def service\_start()

Start a system service.

Arguments

\*args

Arguments to pass to `systemctl start` (normally the service name).

Returns

On success, this function returns True for historical reasons.

#### def service\_stop()

Stop a system service.

Arguments

\*args

Arguments to pass to `systemctl stop` (normally the service name).

Returns

On success, this function returns True for historical reasons.

#### def service\_restart()

Restart a system service.

Arguments

\*args

Arguments to pass to `systemctl restart` (normally the service name).

Returns

On success, this function returns True for historical reasons.

#### def service\_enable()

Enable a system service.

Arguments

\*args

Arguments to pass to `systemctl enable` (normally the service name).

Returns

On success, this function returns True for historical reasons.

#### def service\_disable()

Disable a system service.

Arguments

\*args

Arguments to pass to `systemctl disable` (normally the service name).

Returns

On success, this function returns True for historical reasons.

#### def service\_reload(     service\_name: str,     restart\_on\_failure: bool )

Reload a system service, optionally falling back to restart if reload fails.

Arguments

service\_name

The name of the service to reload.

restart\_on\_failure

Boolean indicating whether to fall back to a restart if the reload fails.

Returns

On success, this function returns True for historical reasons.

#### def service\_pause(service\_name: str)

Pause a system service.

Arguments

service\_name

The name of the service to pause.

Returns

On success, this function returns True for historical reasons.

Description

Stops the service and prevents the service from starting again at boot.

#### def service\_resume(service\_name: str)

Resume a system service.

Arguments

service\_name

The name of the service to resume.

Returns

On success, this function returns True for historical reasons.

Description

Re-enable starting the service again at boot. Start the service.

#### def daemon\_reload()

Reload systemd manager configuration.

Returns

On success, this function returns True for historical reasons.
