Running agents as services using systemd#

Systemd is a new approach to handle services on new versions of Linux, for example, RHEL 7 or later.

Install an agent.

You can configure agents to run as systemd services by defining service scripts, for example, ucdagent.service, ucdserver.service, and so on. Then, place the scripts in the systemd folder. If you are running multiple agents on the system, give the script a unique name, such as ucdagent-A.service.

  1. Create a service script that includes the following parameters:

    Parameter Description
    HOSTNAME The host or system name where the agent or server is running.
    ExecStart The location of the start script in the relevant agent installation directory. Consider these examples, agent-install/bin/agent or agent-install/bin/server, where agent-install is the agent installation location.
    ExecStop The location of the stop script in the relevant agent installation directory. Consider these examples, agent-install/bin/agent or agent-install/bin/server, where agent-install is the agent installation location.
    User The name of the user who runs the agent.
    Group The name of the group that is associated with the user.

    Your script might look like this example:

    ```

    cat /etc/systemd/system/ucdagent.service#

    [Unit] Description=Urbancode Agent Service]

    Define the user and group if not installed using root account.#

    User=ucdadmin   Group=ucdgrp   Type=forking

    Set the HOSTNAME environment variable because it is not set in systemd shell#

    Environment=HOSTNAME=%H

    Call the standard vendor start and stop scripts in the relevant agent install dir#

    ExecStart=/opt/urbancode/bin/agent start ExecStop=/opt/urbancode/bin/agent stop

    The Install session below is required in order to ENABLE the Linux Service#

    [Install]           WantedBy=default.target

    ```

  2. Copy the file into the /etc/systemd/system folder.

  3. Start the agent service.

    For example, to run the ucdagent script, enter the following command:

    systemctl start ucdagent

  4. Set the agent service to autostart after startup.

    For example, if you named the script ucdagent, run the following command:

    systemctl enable ucdagent

The agent runs as a service. To verify that the agent is running as a service, run the following command and verify that two processes from the agent are running:

ps -ef | grep installFolder

For the installFolder variable, specify the installation folder of the agent, such as /opt/ucd/agent.

Parent topic: Installing agents