systemctl启停服务时报错的代码

332 阅读3分钟

systemd-specific exit codes

LSB service exit codes

Exit CodeSymbolic NameDescription
2EXIT_INVALIDARGUMENTInvalid or excess arguments.
3EXIT_NOTIMPLEMENTEDUnimplemented feature.
4EXIT_NOPERMISSIONThe user has insufficient privileges.
5EXIT_NOTINSTALLEDThe program is not installed.
6EXIT_NOTCONFIGUREDThe program is not configured.
7EXIT_NOTRUNNINGThe program is not running.

systemd-specific exit codes

Exit CodeSymbolic NameDescription
200EXIT_CHDIRChanging to the requested working directory failed. See WorkingDirectory= above.
201EXIT_NICEFailed to set up process scheduling priority (nice level). See Nice= above.
202EXIT_FDSFailed to close unwanted file descriptors, or to adjust passed file descriptors.
203EXIT_EXECThe actual process execution failed (specifically, the execve(2) system call). Most likely this is caused by a missing or non-accessible executable file.
204EXIT_MEMORYFailed to perform an action due to memory shortage.
205EXIT_LIMITSFailed to adjust resource limits. See LimitCPU= and related settings above.
206EXIT_OOM_ADJUSTFailed to adjust the OOM setting. See OOMScoreAdjust= above.
207EXIT_SIGNAL_MASKFailed to set process signal mask.
208EXIT_STDINFailed to set up standard input. See StandardInput= above.
209EXIT_STDOUTFailed to set up standard output. See StandardOutput= above.
210EXIT_CHROOTFailed to change root directory (chroot(2)). See RootDirectory=/RootImage= above.
211EXIT_IOPRIOFailed to set up IO scheduling priority. See IOSchedulingClass=/IOSchedulingPriority= above.
212EXIT_TIMERSLACKFailed to set up timer slack. See TimerSlackNSec= above.
213EXIT_SECUREBITSFailed to set process secure bits. See SecureBits= above.
214EXIT_SETSCHEDULERFailed to set up CPU scheduling. See CPUSchedulingPolicy=/CPUSchedulingPriority= above.
215EXIT_CPUAFFINITYFailed to set up CPU affinity. See CPUAffinity= above.
216EXIT_GROUPFailed to determine or change group credentials. See Group=/SupplementaryGroups= above.
217EXIT_USERFailed to determine or change user credentials, or to set up user namespacing. See User=/PrivateUsers= above.
218EXIT_CAPABILITIESFailed to drop capabilities, or apply ambient capabilities. See CapabilityBoundingSet=/AmbientCapabilities= above.
219EXIT_CGROUPSetting up the service control group failed.
220EXIT_SETSIDFailed to create new process session.
221EXIT_CONFIRMExecution has been cancelled by the user. See the systemd.confirm_spawn= kernel command line setting on kernel-command-line(7) for details.
222EXIT_STDERRFailed to set up standard error output. See StandardError= above.
224EXIT_PAMFailed to set up PAM session. See PAMName= above.
225EXIT_NETWORKFailed to set up network namespacing. See PrivateNetwork= above.
226EXIT_NAMESPACEFailed to set up mount, UTS, or IPC namespacing. See ReadOnlyPaths=ProtectHostname=PrivateIPC=, and related settings above.
227EXIT_NO_NEW_PRIVILEGESFailed to disable new privileges. See NoNewPrivileges=yes above.
228EXIT_SECCOMPFailed to apply system call filters. See SystemCallFilter= and related settings above.
229EXIT_SELINUX_CONTEXTDetermining or changing SELinux context failed. See SELinuxContext= above.
230EXIT_PERSONALITYFailed to set up an execution domain (personality). See Personality= above.
231EXIT_APPARMOR_PROFILEFailed to prepare changing AppArmor profile. See AppArmorProfile= above.
232EXIT_ADDRESS_FAMILIESFailed to restrict address families. See RestrictAddressFamilies= above.
233EXIT_RUNTIME_DIRECTORYSetting up runtime directory failed. See RuntimeDirectory= and related settings above.
235EXIT_CHOWNFailed to adjust socket ownership. Used for socket units only.
236EXIT_SMACK_PROCESS_LABELFailed to set SMACK label. See SmackProcessLabel= above.
237EXIT_KEYRINGFailed to set up kernel keyring.
238EXIT_STATE_DIRECTORYFailed to set up unit's state directory. See StateDirectory= above.
239EXIT_CACHE_DIRECTORYFailed to set up unit's cache directory. See CacheDirectory= above.
240EXIT_LOGS_DIRECTORYFailed to set up unit's logging directory. See LogsDirectory= above.
241EXIT_CONFIGURATION_DIRECTORYFailed to set up unit's configuration directory. See ConfigurationDirectory= above.
242EXIT_NUMA_POLICYFailed to set up unit's NUMA memory policy. See NUMAPolicy= and NUMAMask= above.
243EXIT_CREDENTIALSFailed to set up unit's credentials. See LoadCredential= and SetCredential= above.
245EXIT_BPFFailed to apply BPF restrictions. See RestrictFileSystems= above.

BSD exit codes

Exit CodeSymbolic NameDescription
64EX_USAGECommand line usage error
65EX_DATAERRData format error
66EX_NOINPUTCannot open input
67EX_NOUSERAddressee unknown
68EX_NOHOSTHost name unknown
69EX_UNAVAILABLEService unavailable
70EX_SOFTWAREinternal software error
71EX_OSERRSystem error (e.g., can't fork)
72EX_OSFILECritical OS file missing
73EX_CANTCREATCan't create (user) output file
74EX_IOERRInput/output error
75EX_TEMPFAILTemporary failure; user is invited to retry
76EX_PROTOCOLRemote error in protocol
77EX_NOPERMPermission denied
78EX_CONFIGConfiguration error

查看服务脚本内容 (以sshd服务为示例): systemctl cat sshd

# /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.service
Wants=sshd-keygen.service

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

unix.stackexchange.com/questions/7…