@@ -608,16 +608,14 @@ func ConvertContainer(container *parser.UnitFile, isUser bool, unitsInfoMap map[
608
608
// If conmon exited uncleanly it may not have removed the container, so
609
609
// force it, -i makes it ignore non-existing files.
610
610
serviceStopCmd := createBasePodmanCommand (container , ContainerGroup )
611
- serviceStopCmd .add ("rm" , "-v" , "-f" , "-i" , "--cidfile=%t/%N.cid" )
611
+ serviceStopCmd .add ("rm" , "-v" , "-f" , "-i" , containerName )
612
612
service .AddCmdline (ServiceGroup , "ExecStop" , serviceStopCmd .Args )
613
613
// The ExecStopPost is needed when the main PID (i.e., conmon) gets killed.
614
- // In that case, ExecStop is not executed but *Post only. If both are
615
- // fired in sequence, *Post will exit when detecting that the --cidfile
616
- // has already been removed by the previous `rm`..
614
+ // In that case, ExecStop is not executed but *Post only.
617
615
serviceStopCmd .Args [0 ] = fmt .Sprintf ("-%s" , serviceStopCmd .Args [0 ])
618
616
service .AddCmdline (ServiceGroup , "ExecStopPost" , serviceStopCmd .Args )
619
617
620
- if err := handleExecReload (container , service , ContainerGroup ); err != nil {
618
+ if err := handleExecReload (container , service , ContainerGroup , containerName ); err != nil {
621
619
return nil , warnings , err
622
620
}
623
621
@@ -628,9 +626,6 @@ func ConvertContainer(container *parser.UnitFile, isUser bool, unitsInfoMap map[
628
626
podman .add ("--name" , containerName )
629
627
630
628
podman .add (
631
- // We store the container id so we can clean it up in case of failure
632
- "--cidfile=%t/%N.cid" ,
633
-
634
629
// And replace any previous container with the same name, not fail
635
630
"--replace" ,
636
631
@@ -1483,6 +1478,15 @@ func getServiceName(quadletUnitFile *parser.UnitFile, groupName string, defaultE
1483
1478
return removeExtension (quadletUnitFile .Filename , "" , defaultExtraSuffix )
1484
1479
}
1485
1480
1481
+ func GetPodResourceName (podUnit * parser.UnitFile ) string {
1482
+ // Derive pod name from unit name (with added prefix), or use user-provided name.
1483
+ podName , ok := podUnit .Lookup (PodGroup , KeyPodName )
1484
+ if ! ok || len (podName ) == 0 {
1485
+ podName = removeExtension (podUnit .Filename , "systemd-" , "" )
1486
+ }
1487
+ return podName
1488
+ }
1489
+
1486
1490
func ConvertPod (podUnit * parser.UnitFile , name string , unitsInfoMap map [string ]* UnitInfo , isUser bool ) (* parser.UnitFile , error , error ) {
1487
1491
var warn , warnings error
1488
1492
@@ -1491,11 +1495,7 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*
1491
1495
return nil , warnings , err
1492
1496
}
1493
1497
1494
- // Derive pod name from unit name (with added prefix), or use user-provided name.
1495
- podName , ok := podUnit .Lookup (PodGroup , KeyPodName )
1496
- if ! ok || len (podName ) == 0 {
1497
- podName = removeExtension (name , "systemd-" , "" )
1498
- }
1498
+ podName := GetPodResourceName (podUnit )
1499
1499
1500
1500
for _ , containerService := range unitInfo .ContainersToStart {
1501
1501
service .Add (UnitGroup , "Wants" , containerService )
@@ -1507,32 +1507,31 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*
1507
1507
}
1508
1508
1509
1509
execStart := createBasePodmanCommand (podUnit , PodGroup )
1510
- execStart .add ("pod" , "start" , "--pod-id-file=%t/%N.pod-id" )
1510
+ execStart .add ("pod" , "start" , podName )
1511
1511
service .AddCmdline (ServiceGroup , "ExecStart" , execStart .Args )
1512
1512
1513
1513
execStop := createBasePodmanCommand (podUnit , PodGroup )
1514
1514
execStop .add ("pod" , "stop" )
1515
1515
execStop .add (
1516
- "--pod-id-file=%t/%N.pod-id" ,
1517
1516
"--ignore" ,
1518
1517
"--time=10" ,
1518
+ podName ,
1519
1519
)
1520
1520
service .AddCmdline (ServiceGroup , "ExecStop" , execStop .Args )
1521
1521
1522
1522
execStopPost := createBasePodmanCommand (podUnit , PodGroup )
1523
1523
execStopPost .add ("pod" , "rm" )
1524
1524
execStopPost .add (
1525
- "--pod-id-file=%t/%N.pod-id" ,
1526
1525
"--ignore" ,
1527
1526
"--force" ,
1527
+ podName ,
1528
1528
)
1529
1529
service .AddCmdline (ServiceGroup , "ExecStopPost" , execStopPost .Args )
1530
1530
1531
1531
execStartPre := createBasePodmanCommand (podUnit , PodGroup )
1532
1532
execStartPre .add ("pod" , "create" )
1533
1533
execStartPre .add (
1534
1534
"--infra-conmon-pidfile=%t/%N.pid" ,
1535
- "--pod-id-file=%t/%N.pod-id" ,
1536
1535
"--exit-policy=stop" ,
1537
1536
"--replace" ,
1538
1537
)
@@ -2075,7 +2074,7 @@ func handlePod(quadletUnitFile, serviceUnitFile *parser.UnitFile, groupName stri
2075
2074
return fmt .Errorf ("quadlet pod unit %s does not exist" , pod )
2076
2075
}
2077
2076
2078
- podman .add ("--pod-id-file " , fmt . Sprintf ( "%%t/%s.pod-id" , podInfo .ServiceName ) )
2077
+ podman .add ("--pod" , podInfo .ResourceName )
2079
2078
2080
2079
podServiceName := podInfo .ServiceFileName ()
2081
2080
serviceUnitFile .Add (UnitGroup , "BindsTo" , podServiceName )
@@ -2146,7 +2145,7 @@ func addDefaultDependencies(service *parser.UnitFile, isUser bool) {
2146
2145
}
2147
2146
}
2148
2147
2149
- func handleExecReload (quadletUnitFile , serviceUnitFile * parser.UnitFile , groupName string ) error {
2148
+ func handleExecReload (quadletUnitFile , serviceUnitFile * parser.UnitFile , groupName , containerName string ) error {
2150
2149
reloadSignal , signalOk := quadletUnitFile .Lookup (groupName , KeyReloadSignal )
2151
2150
signalOk = signalOk && len (reloadSignal ) > 0
2152
2151
reloadcmd , cmdOk := quadletUnitFile .LookupLastArgs (groupName , KeyReloadCmd )
@@ -2162,10 +2161,10 @@ func handleExecReload(quadletUnitFile, serviceUnitFile *parser.UnitFile, groupNa
2162
2161
2163
2162
serviceReloadCmd := createBasePodmanCommand (quadletUnitFile , groupName )
2164
2163
if cmdOk {
2165
- serviceReloadCmd .add ("exec" , "--cidfile=%t/%N.cid" )
2164
+ serviceReloadCmd .add ("exec" , containerName )
2166
2165
serviceReloadCmd .add (reloadcmd ... )
2167
2166
} else {
2168
- serviceReloadCmd .add ("kill" , "--cidfile=%t/%N.cid" , "-- signal" , reloadSignal )
2167
+ serviceReloadCmd .add ("kill" , "--signal" , reloadSignal , containerName )
2169
2168
}
2170
2169
serviceUnitFile .AddCmdline (ServiceGroup , "ExecReload" , serviceReloadCmd .Args )
2171
2170
0 commit comments