.. _installing-systemd-unit: Using |cp| systemd Service Unit Files ===================================== You can use |cp| `systemd `_ service unit files to configure automatic startup and monitoring of services during system boot. These files are analogous to init scripts or startup scripts and they provide a standardized method for automatically starting |cp| server components in the correct order on startup. .. tip:: The systemd service unit files are optimized for staging and production deployments on Linux-based systems. -------- Overview -------- The systemd service unit files are included in the :ref:`RPM ` and :ref:`Debian packages ` for the following |cp| components: - |c3-short| (``control-center``) - |ak-tm| (``kafka``) - |kconnect-long| (``kafka-connect``) - |crest-long| (``kafka-rest``) - KSQL (``ksql``) - Schema-Registry (``schema-registry``) - |zk| (``zookeeper``) Each component runs under its own user and a common ``confluent`` group that are set up during package installation. This configuration ensures proper security separation between components that are running on the same system. The usernames are prefixed with ``cp-`` followed by the component name. For example, ``cp-kafka`` and ``cp-schema-registry``. For components with persistent storage, such as |ak| and |c3|, the default component configuration file points to component-specific data directories ``/var/lib/``. For example, |ak| points to ``/var/lib/kafka`` and |zk| points to ``/var/lib/zookeeper``. .. note:: This is an enhancement from previous |cp| versions (where the default data directories were non-persistent (``/tmp``) to cater to staging and production deployments. ----- Usage ----- Enabling Automatic Startup During Boot -------------------------------------- During installation, a component service is not enabled for automatic start on boot by default. To enable startup on boot, but not immediately, run this command. .. code:: bash sudo systemctl enable confluent- For example, you can enable the |crest-long| with the command: .. code:: bash sudo systemctl enable confluent-kafka-rest Starting Service Immediately ---------------------------- To start the service now, run this command: .. code:: bash sudo systemctl start confluent- This command will return immediately, although the service has not been started. The actual starting of the service is performed in the background by the systemd daemon. Checking Service Status ----------------------- To check the status of a service, run this command: .. code:: bash systemctl status confluent- Look for the ``Active:`` line, which should say ``active``. Stopping a Service ------------------ To stop a service, run this command: .. code:: bash sudo systemctl stop confluent- Disabling a Service ------------------- To disable a service to prevent it from being automatically started on boot, run this command: .. code:: bash sudo systemctl disable confluent- ------- Logging ------- Log files are located in component-specific directories ``/var/log/confluent/``. For example, |sr| logs are located in ``/var/log/confluent/schema-registry``. The standard output of services is written to the log journal of a service. You can read the log journal with this command: .. code:: bash sudo journalctl -u confluent- Following the Log ----------------- To follow the log in real-time, run this command: .. code:: bash sudo journalctl -f -u confluent- ----------------------- Modifying Configuration ----------------------- Modifying Service Unit Configuration Settings --------------------------------------------- To make changes to the service unit configuration settings, you should append configuration settings that overwrite previous defaults, rather than change existing configuration lines. This assures that the base service unit files can be upgraded cleanly. .. tip:: The systemd component configuration settings are minimal and only control how the component is started, run, and stopped. The component configuration is managed through its existing ``/etc//.properties`` configuration file, for example ``/etc/kafka/server.properties`` for the |ak| broker. Modifying the Systemd Component Configuration --------------------------------------------- To modify the configuration settings for a service using the systemd builtin configuration editor, follow these steps: #. View the current systemd component configuration: .. code:: bash systemctl cat confluent- #. Run the edit command: .. code:: bash sudo systemctl edit confluent- #. Optional: Inspect the result. .. code:: bash systemctl cat confluent- #. Reload systemd configuration and restart the component. .. code:: bash sudo systemctl reload sudo systemctl restart confluent- .. tip:: To reconfigure the |cp| component, refer to the component documentation and its configuration file. The configuration files are located in ``/etc//.properties``. After reconfiguring the component, restart it with the following command to have the changes take affect: .. code:: bash sudo systemctl restart confluent- -------------------- Additional Resources -------------------- * For more information about systemd, see `https://www.freedesktop.org/wiki/Software/systemd/ `_. * To see a working example of the systemd unit files in combination with Ansible, see the :ref:`Confluent Platform Ansible playbooks ` (No Confluent support, community support only).