![如何列出 systemd @.service 单位?](https://linux22.com/image/164904/%E5%A6%82%E4%BD%95%E5%88%97%E5%87%BA%20systemd%20%40.service%20%E5%8D%95%E4%BD%8D%EF%BC%9F.png)
我很早以前写过一个“动态”服务单元。然后我启用了该单元的一些变体,例如或。/etc/systemd/system/[email protected]
[email protected]
[email protected]
然后我就忘了我启用了什么。
如何列出从@.service
条目派生的单位?
我知道它们存在是因为
- 他们启动我看到在我的系统上运行的服务
- 对于我记得的人来说,运行
systemctl show myunit@hello
会输出正确的信息。
我认为systemctl
或systemctl list-units --type service --all
或systemctl list-unit-files | grep enabled
会列出它们 - 但他们没有。我[email protected]
在输出中没有看到(尽管show
提供了正确的信息)
这些单位是“oneshot”单位 - 命令ExecStart
完成其工作并退出(我现在意识到单位的类型未设置 - 但它可以工作,因此默认值是可以的)
该命令的输出show
与动态定义非常匹配:
/etc/systemd/system # systemctl show docker-compose@domotique root@srv
Type=simple
Restart=no
NotifyAccess=none
RestartUSec=100ms
TimeoutStartUSec=5s
TimeoutStopUSec=5s
RuntimeMaxUSec=infinity
WatchdogUSec=0
WatchdogTimestampMonotonic=0
PermissionsStartOnly=no
RootDirectoryStartOnly=no
RemainAfterExit=no
GuessMainPID=yes
MainPID=0
ControlPID=0
FileDescriptorStoreMax=0
NFileDescriptorStore=0
StatusErrno=0
Result=success
UID=[not set]
GID=[not set]
NRestarts=0
ExecMainStartTimestampMonotonic=0
ExecMainExitTimestampMonotonic=0
ExecMainPID=0
ExecMainCode=0
ExecMainStatus=0
ExecStartPre={ path=/usr/local/bin/docker-compose ; argv[]=/usr/local/bin/docker-compose -f /etc/docker/docker-compose-domotique.yaml pull --ignore-pull-failures ; ignore_errors=
ExecStart={ path=/usr/local/bin/docker-compose ; argv[]=/usr/local/bin/docker-compose -f /etc/docker/docker-compose-domotique.yaml up -d ; ignore_errors=no ; start_time=[n/a] ; s
Slice=system-docker\x2dcompose.slice
MemoryCurrent=[not set]
CPUUsageNSec=[not set]
TasksCurrent=[not set]
IPIngressBytes=18446744073709551615
IPIngressPackets=18446744073709551615
IPEgressBytes=18446744073709551615
IPEgressPackets=18446744073709551615
Delegate=no
CPUAccounting=no
CPUWeight=[not set]
StartupCPUWeight=[not set]
CPUShares=[not set]
StartupCPUShares=[not set]
CPUQuotaPerSecUSec=infinity
IOAccounting=no
IOWeight=[not set]
StartupIOWeight=[not set]
BlockIOAccounting=no
BlockIOWeight=[not set]
StartupBlockIOWeight=[not set]
MemoryAccounting=no
MemoryLow=0
MemoryHigh=infinity
MemoryMax=infinity
MemorySwapMax=infinity
MemoryLimit=infinity
DevicePolicy=auto
TasksAccounting=yes
TasksMax=4915
IPAccounting=no
UMask=0022
LimitCPU=infinity
LimitCPUSoft=infinity
LimitFSIZE=infinity
LimitFSIZESoft=infinity
LimitDATA=infinity
LimitDATASoft=infinity
LimitSTACK=infinity
LimitSTACKSoft=8388608
LimitCORE=infinity
LimitCORESoft=0
LimitRSS=infinity
LimitRSSSoft=infinity
LimitNOFILE=4096
LimitNOFILESoft=1024
LimitAS=infinity
LimitASSoft=infinity
LimitNPROC=31230
LimitNPROCSoft=31230
LimitMEMLOCK=16777216
LimitMEMLOCKSoft=16777216
LimitLOCKS=infinity
LimitLOCKSSoft=infinity
LimitSIGPENDING=31230
LimitSIGPENDINGSoft=31230
LimitMSGQUEUE=819200
LimitMSGQUEUESoft=819200
LimitNICE=0
LimitNICESoft=0
LimitRTPRIO=0
LimitRTPRIOSoft=0
LimitRTTIME=infinity
LimitRTTIMESoft=infinity
WorkingDirectory=/etc/docker
OOMScoreAdjust=0
Nice=0
IOSchedulingClass=0
IOSchedulingPriority=0
CPUSchedulingPolicy=0
CPUSchedulingPriority=0
TimerSlackNSec=50000
CPUSchedulingResetOnFork=no
NonBlocking=no
StandardInput=null
StandardInputData=
StandardOutput=journal
StandardError=inherit
TTYReset=no
TTYVHangup=no
TTYVTDisallocate=no
SyslogPriority=30
SyslogLevelPrefix=yes
SyslogLevel=6
SyslogFacility=3
LogLevelMax=-1
SecureBits=0
CapabilityBoundingSet=cap_chown cap_dac_override cap_dac_read_search cap_fowner cap_fsetid cap_kill cap_setgid cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service cap
AmbientCapabilities=
DynamicUser=no
RemoveIPC=no
MountFlags=
PrivateTmp=no
PrivateDevices=no
ProtectKernelTunables=no
ProtectKernelModules=no
ProtectControlGroups=no
PrivateNetwork=no
PrivateUsers=no
ProtectHome=no
ProtectSystem=no
SameProcessGroup=no
UtmpMode=init
IgnoreSIGPIPE=yes
NoNewPrivileges=no
SystemCallErrorNumber=0
LockPersonality=no
RuntimeDirectoryPreserve=no
RuntimeDirectoryMode=0755
StateDirectoryMode=0755
CacheDirectoryMode=0755
LogsDirectoryMode=0755
ConfigurationDirectoryMode=0755
MemoryDenyWriteExecute=no
RestrictRealtime=no
RestrictNamespaces=no
MountAPIVFS=no
KeyringMode=private
KillMode=control-group
KillSignal=15
SendSIGKILL=yes
SendSIGHUP=no
[email protected]
[email protected]
Requires=sysinit.target docker.service system-docker\x2dcompose.slice -.mount
Conflicts=shutdown.target
Before=shutdown.target
After=basic.target network.target system-docker\x2dcompose.slice sysinit.target -.mount systemd-journald.socket
RequiresMountsFor=/etc/docker
Description=docker compose startup for domotique
LoadState=loaded
ActiveState=inactive
SubState=dead
FragmentPath=/etc/systemd/system/[email protected]
UnitFileState=disabled
UnitFilePreset=enabled
StateChangeTimestampMonotonic=0
InactiveExitTimestampMonotonic=0
ActiveEnterTimestampMonotonic=0
ActiveExitTimestampMonotonic=0
InactiveEnterTimestampMonotonic=0
CanStart=yes
CanStop=yes
CanReload=no
CanIsolate=no
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=no
NeedDaemonReload=no
JobTimeoutUSec=infinity
JobRunningTimeoutUSec=infinity
JobTimeoutAction=none
ConditionResult=no
AssertResult=no
ConditionTimestampMonotonic=0
AssertTimestampMonotonic=0
Transient=no
Perpetual=no
StartLimitIntervalUSec=10s
StartLimitBurst=5
StartLimitAction=none
FailureAction=none
SuccessAction=none
CollectMode=inactive
/etc/systemd/system # cat /etc/systemd/system/[email protected] root@srv
[Unit]
Description=docker compose startup for %i
After=network.target
Requires=docker.service
[Service]
ExecStartPre=-/usr/local/bin/docker-compose -f /etc/docker/docker-compose-%i.yaml pull --ignore-pull-failures
ExecStart=/usr/local/bin/docker-compose -f /etc/docker/docker-compose-%i.yaml up -d
WorkingDirectory=/etc/docker
[Install]
WantedBy=multi-user.target
答案1
我建议systemctl status myunit@*.service
例如。请参阅 中的“全局模式” man systemctl
。
如果您使用标准 shell 并且当前目录中可能myunit@*.service
存在匹配的文件,那么您可能需要逃脱通过使用来代替元*
字符\*
。如果您一直这样做并没有什么害处,但会增加一点额外的打字量。