mkunit target
Create a systemd target unit to group related units together.
mkunit target <name> [flags]
Description
The target command creates a .target unit file for grouping
related services together. Targets are synchronization points that allow you to start
or stop multiple units at once, similar to runlevels in SysV init.
Arguments
| Argument | Description |
|---|---|
<name> |
Name of the target (without .target extension) |
Flags
| Flag | Description | Default |
|---|---|---|
--description <text> |
Human-readable description | Auto-generated |
--requires <unit> |
Require this unit (can be repeated) | — |
--wants <unit> |
Want this unit (can be repeated) | — |
--after <unit> |
Start after this unit (can be repeated) | — |
--before <unit> |
Start before this unit (can be repeated) | — |
--conflicts <unit> |
Conflicts with this unit | — |
--allow-isolate |
Allow systemctl isolate to this target |
false |
--system |
Create a system target | false |
--install |
Install the unit file | false |
--start |
Activate the target | false |
--enable |
Enable on boot | false |
--dry-run |
Print without writing | false |
Common System Targets
These are built-in systemd targets you can reference:
| Target | Description |
|---|---|
multi-user.target | Non-graphical multi-user system |
graphical.target | Graphical desktop |
network.target | Network is configured |
network-online.target | Network is fully online |
default.target | Default boot target (user sessions) |
Examples
Group related services
# Create a target for your application stack
mkunit target myapp-stack \
--description "My Application Stack" \
--wants myapp-api.service \
--wants myapp-worker.service \
--wants myapp-scheduler.service \
--install
Then start all services at once:
systemctl --user start myapp-stack.target
Create a custom boot target
sudo mkunit target development \
--description "Development Environment" \
--requires multi-user.target \
--wants docker.service \
--wants postgresql.service \
--wants redis.service \
--allow-isolate \
--system --install
Switch to this target:
sudo systemctl isolate development.target
Define services that belong to a target
The recommended way is to have services declare which target they belong to:
# Create the target
mkunit target myapp --install
# Create services that belong to it
mkunit service myapp-api \
--exec "./api" \
--wanted-by myapp.target \
--install
mkunit service myapp-worker \
--exec "./worker" \
--wanted-by myapp.target \
--install
Ordering with other targets
mkunit target database-ready \
--description "Databases are ready" \
--wants postgresql.service \
--wants redis.service \
--after postgresql.service \
--after redis.service \
--install
Tip
Use Wants= for services that should start with the target but aren't required.
Use Requires= for services that must be running for the target to be active.
See Also
- mkunit service - Create services that belong to targets
- mkunit status - Check target status
man systemd.target- Full target unit documentation