[[running-with-systemd]]
=== {beatname_uc} and systemd

The DEB and RPM packages include a service unit for Linux systems with
systemd. On these systems, you can manage {beatname_uc} by using the usual
systemd commands.

==== Start and stop {beatname_uc}

Use `systemctl` to start or stop {beatname_uc}:

["source", "sh", subs="attributes"]
------------------------------------------------
systemctl start {beatname_pkg}
------------------------------------------------

["source", "sh", subs="attributes"]
------------------------------------------------
systemctl stop {beatname_pkg}
------------------------------------------------

By default, the {beatname_uc} service starts automatically when the system
boots. To enable or disable auto start use:

["source", "sh", subs="attributes"]
------------------------------------------------
systemctl enable {beatname_pkg}
------------------------------------------------

["source", "sh", subs="attributes"]
------------------------------------------------
systemctl disable {beatname_pkg}
------------------------------------------------


==== {beatname_uc} status and logs

To get the service status, use `systemctl`:

["source", "sh", subs="attributes"]
------------------------------------------------
systemctl status {beatname_pkg}
------------------------------------------------

Logs are stored by default in journald. To view the Logs, use `journalctl`:

["source", "sh", subs="attributes"]
------------------------------------------------
journalctl -u {beatname_pkg}.service
------------------------------------------------

[float]
=== Customize systemd unit for {beatname_uc}

The systemd service unit file includes environment variables that you can
override to change the default options.

[cols="<h,<,<m",options="header",]
|=======================================
| Variable | Description | Default value
| BEAT_LOG_OPTS | Log options |
| BEAT_CONFIG_OPTS | Flags for configuration file path | +-c /etc/{beatname_lc}/{beatname_lc}.yml+
| BEAT_PATH_OPTS | Other paths | +-path.home /usr/share/{beatname_lc} -path.config /etc/{beatname_lc} -path.data /var/lib/{beatname_lc} -path.logs /var/log/{beatname_lc}+
|=======================================

NOTE: You can use `BEAT_LOG_OPTS` to set debug selectors for logging. However,
to configure logging behavior, set the logging options described in
<<configuration-logging,Configure logging>>.

To override these variables, create a drop-in unit file in the
+/etc/systemd/system/{beatname_pkg}.service.d+ directory.  

For example a file with the following content placed in
+/etc/systemd/system/{beatname_pkg}.service.d/debug.conf+
would override `BEAT_LOG_OPTS` to enable debug for Elasticsearch output.

["source", "systemd", subs="attributes"]
------------------------------------------------
[Service]
Environment="BEAT_LOG_OPTS=-d elasticsearch"
------------------------------------------------

To apply your changes, reload the systemd configuration and restart
the service:

["source", "sh", subs="attributes"]
------------------------------------------------
systemctl daemon-reload
systemctl restart {beatname_pkg}
------------------------------------------------

NOTE: It is recommended that you use a configuration management tool to
include drop-in unit files. If you need to add a drop-in manually, use
+systemctl edit {beatname_pkg}.service+.
