Back to Etcd

Exit Codes Reference

Documentation/contributor-guide/exit_codes.md

3.7.05.3 KB
Original Source

Exit Codes Reference

This document provides a reference of exit codes returned by the etcd server.

etcd server explicitly uses three exit codes: 0 (success), 1 (general errors), and 2 (argument errors). When terminated by signals (SIGTERM/SIGINT) on Linux/Unix systems, the exit code depends on the process type: PID 1 processes exit with code 0, while non-PID 1 processes re-raise the signal, resulting in exit codes 143 (SIGTERM) or 130 (SIGINT).

Exit Code 0 - Success

ScenarioCode Reference
Help flag (--help)server/etcdmain/config.go#L131
Version flag (--version)server/etcdmain/config.go#L144
Normal shutdownserver/etcdmain/etcd.go#L176
Graceful shutdown on signal (PID 1)pkg/osutil/interrupt_unix.go#L74

Signal Termination (128 + signal number)

Note: This behavior is specific to Linux platform. On other platforms, etcd typically returns exit code 0 if it exits without error, and 1 otherwise.

For non-PID 1 processes on Linux/Unix, the signal handler re-raises the signal to the process itself (pkg/osutil/interrupt_unix.go#L77), which results in the kernel setting the exit code to 128 + signal number.

SignalExit CodeCode Reference
SIGINT (Ctrl-C)130 (128 + 2)pkg/osutil/interrupt_unix.go#L53
SIGTERM143 (128 + 15)pkg/osutil/interrupt_unix.go#L53

Exit Code 1 - General Errors

All server errors exit with code 1:

ScenarioCode Reference
Failed to create loggerserver/etcdmain/etcd.go#L60
Failed to verify flagsserver/etcdmain/etcd.go#L69
Discovery token already usedserver/etcdmain/etcd.go#L141
Initial cluster configuration errorserver/etcdmain/etcd.go#L155
Discovery failedserver/etcdmain/etcd.go#L157
Listener failedserver/etcdmain/etcd.go#L172
Failed to list data directoryserver/etcdmain/etcd.go#L201
Invalid datadir (member + proxy exist)server/etcdmain/etcd.go#L221
Unsupported architectureserver/etcdmain/etcd.go#L252
Generic fatal errorserver/etcdmain/util.go#L34
Invalid listen-peer-urlsserver/embed/config.go#L821
Invalid listen-client-urlsserver/embed/config.go#L830
Invalid listen-client-http-urlsserver/embed/config.go#L839
Invalid initial-advertise-peer-urlsserver/embed/config.go#L848
Invalid advertise-client-urlsserver/embed/config.go#L857
Invalid listen-metrics-urlsserver/embed/config.go#L866

Exit Code 2 - Argument Errors

ScenarioCode Reference
Flag parsing errorserver/etcdmain/config.go#L133