β (beta)
A CLI tool that helps you manage services on Alpine Linux by translating systemd commands to their OpenRC equivalents.
systemctl-alpine bridges the gap between systemd and OpenRC service management by providing a familiar systemd-like interface for Alpine Linux. It allows you to:
- Convert systemd service files to OpenRC init scripts
- Enable and disable services
- Start, stop, restart, and check the status of services
- Check if services are active and view their detailed properties
- List all available services and their status (both enabled and installed)
- Query service states and properties in a systemd-compatible way
- Edit OpenRC service scripts with modification tracking
- Work with template services (e.g.,
nginx@.service)
This tool is particularly useful for:
- Docker container images transitioning from systemd-based distributions to Alpine Linux
- Developers familiar with systemd who need to work with Alpine Linux
- Automation scripts that use systemd commands but need to run on Alpine
- Go 1.24 or higher
- Alpine Linux (tested on version 3.20 and above)
- Root/sudo access for service management
Clone the repository
git clone https://github.com/mobydeck/systemctl-alpine.git
cd systemctl-alpineBuild the binary
go build -o systemctl-alpineInstall it to your PATH
sudo mv systemctl-alpine /bin/systemctlsystemctl is a CLI tool that helps you manage services on Alpine Linux
by translating systemctl commands to their OpenRC equivalents.
For example, you can use 'systemctl enable some-service' to convert a systemd
service file to an OpenRC init script and enable it to start at boot.
Usage:
systemctl [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
daemon-reload Reload systemd manager configuration (not needed in OpenRC)
disable Disable one or more services from starting at boot
edit Edit an OpenRC service script
enable Enable one or more services to start at boot
help Help about any command
is-active Check if a service is currently active (running)
is-enabled Check if a service is enabled to start at boot
list List all systemd services and their OpenRC status
list-unit-files List all installed unit files and their enablement state
list-units List loaded systemd units
reload Reload a service
restart Restart a service
show Show properties of a service or the service manager
start Start a service
status Check the status of a service
stop Stop a service
Flags:
-h, --help help for systemctl
Use "systemctl [command] --help" for more information about a command.
Enable a service (converts systemd service file to OpenRC and enables it)
systemctl enable nginxEnable a template service with an instance name
systemctl enable nginx@user1Enable and start a service
systemctl enable --now nginxForce enable a service (overwrite manually modified service files)
systemctl enable --force nginxStart a service
systemctl start nginxStop a service
systemctl stop nginxRestart a service
systemctl restart nginxCheck service status
systemctl status nginxReload service configuration
systemctl reload nginxDisable a service
systemctl disable nginxDisable and stop a service
systemctl disable --now nginxCheck if a service is enabled
systemctl is-enabled nginxCheck if a service is currently active (running)
systemctl is-active nginxShow service properties
systemctl show nginxShow specific properties of a service
systemctl show nginx -p ActiveState
systemctl show nginx --property=UnitFileState --property=Type
systemctl show nginx --property=ActiveState --valueShow systemd manager properties
systemctl showEdit a service script
systemctl edit nginxList services
# List enabled OpenRC services and all systemd services
systemctl list
# List all services including disabled OpenRC services
systemctl list --all
systemctl ls -a
# The output shows service status and origin for converted services
SERVICE STATUS
nginx enabled
redis enabled (from /lib/systemd/system/redis.service)
mysql disabled
apache2 disabled (not converted)List unit files
# List all installed unit files with their enablement state
systemctl list-unit-files
# List only enabled service unit files
systemctl list-unit-files --type=service --state=enabled
# The output shows each unit file and its state
UNIT FILE STATE
nginx.service enabled
redis.service enabled
mysql.service disabled
custom.service staticList units
# List all active and enabled units
systemctl list-units
# List all units including inactive ones
systemctl list-units --all
# List only failed units
systemctl list-units --state=failed
# List only running services
systemctl list-units --type=service --state=running
# The output shows detailed status of each unit
UNIT LOAD ACTIVE SUB DESCRIPTION
nginx.service loaded active running nginx web server
redis.service loaded active running Redis data structure store
mysql.service loaded inactive dead MySQL database serverYou can enable or disable multiple services at once:
Enable multiple services
systemctl enable nginx mysql redisEnable and start multiple services
systemctl enable --now nginx mysql redisDisable multiple services
systemctl disable nginx mysql redisDisable and stop multiple services
systemctl disable --now nginx mysql redisThe tool looks for systemd service files in these locations:
/lib/systemd/system//etc/systemd/system/
When you run systemctl enable some-service:
- The tool looks for
some-service.servicein the standard systemd locations - If a systemd service file is found:
- It parses the systemd service file and extracts key configuration
- It generates an equivalent OpenRC init script
- It installs the script to
/etc/init.d/some-service
- If no systemd service file is found but an OpenRC service exists:
- It skips the conversion step and just enables the existing OpenRC service
- It enables the service using
rc-update add some-service default - If the
--nowflag is used, it also starts the service
For template services like nginx@.service, when you run systemctl enable nginx@user1:
- The tool looks for the template service file
nginx@.service - It processes the template, substituting variables like
%iwith the instance nameuser1 - It creates an OpenRC service script named
nginx@user1with the instance name available as an environment variable
For other commands like start, stop, etc., it translates them to the appropriate rc-service commands.
When you run systemctl edit some-service:
- The tool opens the OpenRC service script in an editor (using
$EDITOR,vi,nano, ored) - After editing, it adds a modification comment with a timestamp to track changes
- If you edit the file again, it updates the timestamp to reflect the most recent edit
When you run systemctl enable some-service on a service that has been manually edited:
- The tool detects the modification comment and avoids overwriting your changes
- It notifies you that the service has been manually modified
- It enables the existing service without converting it again
- If you want to force a conversion, you can use the
--forceflag
This protection ensures that your manual customizations to service scripts are preserved.
- Service Conversion: Converts systemd service files to OpenRC init scripts
- ExecStop Support: Properly handles custom stop commands from systemd services
- Reload Support: Implements service reloading via SIGHUP
- Multiple Service Management: Enable or disable multiple services with a single command
- Smart Listing: Shows all systemd services and enabled OpenRC services by default, with an option to show all services
- Service State Querying: Check if services are active or view their detailed properties (
is-active,show) - Unit File Inspection: List all installed unit files with their enablement state (
list-unit-files) - Unit Listing: Display loaded and active units with comprehensive status information (
list-units) - Existing Service Detection: Works with existing OpenRC services even without systemd service files
- Service Type Support: Handles different systemd service types (simple, forking, notify)
- Capabilities Support: Converts systemd AmbientCapabilities to OpenRC capabilities
- Edit Command: Edit OpenRC service scripts with your preferred editor
- Modification Protection: Prevents automatic overwriting of manually edited service scripts
- Template Services: Supports systemd template services with instance names and variable substitution
- Property Inspection: View service properties in systemd-compatible key=value format with filtering options
The following systemd service directives are supported in the conversion process:
| Systemd Directive | OpenRC Equivalent | Notes |
|---|---|---|
| Description | description | Service description |
| User | command_user | User to run the service as |
| Group | command_user | Group to run the service as (combined with User) |
| WorkingDirectory | directory | Directory to run the service in |
| EnvironmentFile | Sourced in script | Environment file for the service |
| Environment | export statements | Environment variables |
| ExecStartPre | start_pre() | Commands to run before starting the service |
| ExecStart | command/command_args | Main service command |
| ExecStop | stop() | Custom stop command |
| Type | command_background | Affects whether service runs in background |
| AmbientCapabilities | capabilities | Linux capabilities for the service |
Type=simpleorType=notify(or no Type): Setscommand_background=truein OpenRCType=forking: Omitscommand_backgroundas the service handles its own daemonization
Systemd's space-separated capabilities list is converted to OpenRC's comma-separated format with the ^ prefix:
# Systemd
AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_SYS_TIME
# Converted to OpenRC
capabilities="^cap_net_bind_service,^cap_sys_time"
When processing template services, the following systemd specifiers are supported:
| Specifier | Description | Example |
|---|---|---|
%i |
Instance name | For nginx@user1, this is user1 |
%I |
Unescaped instance name | Same as %i but with systemd escaping undone |
%p |
Prefix name | For nginx@user1, this is nginx |
%P |
Unescaped prefix name | Same as %p but with systemd escaping undone |
%n |
Full unit name | For nginx@user1, this is nginx@user1.service |
%N |
Unit name without type suffix | For nginx@user1.service, this is nginx@user1 |
%a |
Architecture | x86_64, aarch64, etc. |
%l |
Short hostname | Hostname without domain part |
%m |
Machine ID | Contents of /etc/machine-id |
%o |
Operating system ID | From /etc/os-release, e.g., alpine |
%% |
Percent sign | Literal % character |
The instance name is also made available as the INSTANCE environment variable in the OpenRC script.
- Not all systemd features are supported in the conversion process
- Some complex systemd unit files may require manual adjustment after conversion
- Socket activation is not supported
- Timer units are not supported
- Open an issue on GitHub with:
- The command you ran
- The complete error message
- Your Alpine Linux version
- The content of your systemd service file
Contributions are welcome! Please feel free to submit a Pull Request.