# Unit File Types - `automount` - `device` - `mount` - `path` - `scope` - `service` - `slice` - `snapshot` - `socket` - `swap` - `target` - group of services to load - `timer` - cron analogue # Listing & Viewing Unit Files - `sudo systemctl get-default` shows default boot target unit file ![[images/Pasted image 20250805205022.png]] - common targets: - `multi-user.target` - `graphical.target` - `rescue.target` - `emergency.target` - `sudo systemctl list-units` shows current unit info ![[images/Pasted image 20250806194911.png]] - `systemctl list-unit-files` shows current unit files ![[images/Pasted image 20250805204320.png]] - unit files show associated location in `/lib/systemd/system` - unit files include three primary section: `[Unit]`, `[Service]`, and `[Install]` - `sudo systemctl cat name.service` to view unit file ![[images/Pasted image 20250805204531.png]] - `sudo systemctl cat name.timer` to view timer unit file ![[images/Pasted image 20250806195518.png]] - `sudo systemctl stats *timer` to show all `systemd` timer units - `sudo systemctl cat name.mount` to view mount unit file ![[images/Pasted image 20250806195902.png]] - `sudo systemctl stats *mount` to show all `systemd` mount units - `sudo systemctl cat name.target` to view target unit file ![[images/Pasted image 20250806202310.png]] # Unit File Sections Explained - unit files include three primary section: `[Unit]`, `[Service]`, and `[Install]` ## Common `[Unit]` directives | Directive | Description | | --------------- | ---------------------------------------------------------------------------------------- | | `After` | sets this unit to start after designated units | | `Before` | sets this unit to start before designated units | | `Description` | describes the unit | | `Documentation` | sets list of URIs that point to documentation for the unit | | `Conflicts` | sets this unit to not start with designated units | | `Requires` | sets this unit to start together with designated units (must start with other) | | `Wants` | sets this unit to start together with designated units (will still start without others) | ## Common `[Service]` directives | Directive | Description | | ------------- | ----------------------------------------------------------------------- | | `ExecReload` | indicates scripts or commands to run when unit is reloaded | | `ExecStart` | indicates scripts or commands to run when unit is started | | `ExecStop` | indicates scripts or commands to run when unit is stopped | | `Environment` | sets environment variable substitutes | | `Restart` | service is restarted when the process started by `ExecStart` terminates | | `Type` | sets startup type | ## Common `[Install]` directives | Directive | Description | | ------------ | ------------------------------------------------------------------------------------ | | `Alias` | sets additional names that can be used to denote the service in `systemctl` commands | | `Also` | sets additional units that must be enabled or disabled for this service | | `RequiredBy` | designates other units that require this service | | `WantedBy` | designates which target unit manages this service |