Skip to main content

Colcon plugin that generates systemd service units for opted-in packages during colcon build

Project description

colcon-systemd

Colcon plugin that generates systemd service units for opted-in packages during colcon build, installable with pip install.

Installation

From PyPI (once published)

Install into your current Python environment (the same one where colcon is installed):

pip install colcon-systemd

This installs the plugin into your user or virtualenv site-packages — it does not install anything system-wide or require root. colcon discovers the plugin automatically via entry points.

From Source (development)

git clone https://github.com/CraigBuilds/colcon-systemd.git
cd colcon-systemd
pip install -e ".[test]"

The -e (editable) flag means changes you make to the source take effect immediately without reinstalling. Run this from the cloned colcon-systemd/ directory.

Verifying the Installation

After installing, confirm colcon can see the plugin:

colcon build --event-handlers systemd+
# You should not get "unknown event handler" errors

Quick Start

1. Add a Config File to Your Package

In the source root of a ROS 2 / colcon package (next to package.xml), create a colcon-systemd.yaml:

services:
  - name: my_node
    entry_point: my_node          # console_scripts entry point name
    description: "My ROS 2 node"
    environment:
      ROS_DOMAIN_ID: "0"
    restart: on-failure

2. Build from Your Workspace Root

Run colcon build from the workspace root (the directory that contains src/, or wherever your packages live — the same place you'd normally run colcon build):

cd ~/my_ros2_ws    # your colcon workspace root
colcon build

The plugin runs automatically for any package that contains a colcon-systemd.yaml file. Packages without the file are unaffected.

3. Find the Generated Files

The generated service files are written into the colcon install tree — they are never written to /etc/systemd/system or any system directory:

install/<pkg>/share/colcon-systemd/my_node.service   # systemd unit
install/<pkg>/share/colcon-systemd/my_node.sh         # wrapper script

4. Activate the Service (Optional)

To actually run the service with systemd, symlink the unit into your user systemd directory:

mkdir -p ~/.config/systemd/user
ln -s "$(pwd)/install/<pkg>/share/colcon-systemd/my_node.service" \
      ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user start my_node
systemctl --user status my_node

This uses systemctl --user, which does not require root.

Configuration Reference

Each service in colcon-systemd.yaml accepts:

Field Required Default Description
name Yes Service name (alphanumeric, hyphens, underscores)
entry_point One of entry_point/executable console_scripts entry point name
executable One of entry_point/executable Executable name
description No <pkg> <name> systemd unit description
after No [network.target] systemd After= dependencies
environment No {} Environment variables
restart No on-failure systemd restart policy
working_directory No Working directory for the service

How It Works

colcon-systemd registers as a colcon event handler extension. During colcon build, it listens for successful build completions (JobEnded events with rc == 0). For each package that has a colcon-systemd.yaml file, it:

  1. Parses and validates the configuration
  2. Generates a bash wrapper script that sources setup.bash and execs the entry point
  3. Generates a systemd .service unit file that runs the wrapper script

This approach uses direct execution of the installed entry point rather than ros2 run, for simpler signal handling and no runtime dependency on the ros2 CLI. See DESIGN.md for detailed rationale.

Supported Package Types

Type Support
ros.ament_python Primary (best tested)
python Full
ros.ament_cmake Full
cmake Full
ros.catkin Full

Other types generate a warning but still produce units.

Disabling the Extension

colcon build --event-handlers systemd-

Testing

pip install -e ".[test]"
pytest tests/ -v

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

colcon_systemd-0.1.0.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

colcon_systemd-0.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file colcon_systemd-0.1.0.tar.gz.

File metadata

  • Download URL: colcon_systemd-0.1.0.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for colcon_systemd-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9cce4ccd38f57a1a4c4f6fce0a580fed83f98dcc38182cc0fe0f82c7c35a2fa8
MD5 64f4ddbeb03f44b7077f929b26810e57
BLAKE2b-256 ba2f01049bbbeb2da997c58dbc26847052cfc7e30511a87f275c6956a33c7dc3

See more details on using hashes here.

Provenance

The following attestation bundles were made for colcon_systemd-0.1.0.tar.gz:

Publisher: release.yml on CraigBuilds/colcon-systemd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file colcon_systemd-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: colcon_systemd-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for colcon_systemd-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b14578447e66f202a1c9cf6673bafe5f7d40d21c921add53eb0cbe081bb5a9db
MD5 ce80bae2f52cc560967ee6d30d2443a3
BLAKE2b-256 9040c67415a82545ae4d1750e2f67fcf1a15271867ec30b017d92d9ec4d2e619

See more details on using hashes here.

Provenance

The following attestation bundles were made for colcon_systemd-0.1.0-py3-none-any.whl:

Publisher: release.yml on CraigBuilds/colcon-systemd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page