@@ -166,6 +166,22 @@ domainXsPath uuid = do
166166 " " -> return $ " /local/domain/unknown"
167167 _ -> return $ " /local/domain/" ++ domid
168168
169+ pushPowerButton :: Uuid -> Int -> IO ()
170+ pushPowerButton uuid count = do
171+ domid <- getDomainId uuid
172+ stubdomid <- getStubDomainID uuid
173+ let xs_path = " /local/domain/" ++ stubdomid ++ " /device-model/" ++ domid
174+ _pushPowerButton uuid domid xs_path 1 count
175+ where
176+ _pushPowerButton :: Uuid -> String -> String -> Int -> Int -> IO ()
177+ _pushPowerButton uuid domid xs_path i max = do
178+ debug $ " push power button " ++ show uuid ++ " " ++ show i ++ " of " ++ show max
179+ xsWrite (xs_path ++ " /hvm-shutdown" ) " poweroff"
180+ system_ (" xl trigger " ++ domid ++ " power" )
181+ if i < max
182+ then do threadDelay $ 10 ^ 6
183+ _pushPowerButton uuid domid xs_path ( i + 1 ) max
184+ else return ()
169185
170186-- The following functions are all domain lifecycle operations, and self-explanatory
171187
@@ -190,8 +206,7 @@ shutdown uuid =
190206 Just g -> do exitCode <- system_ (" xl shutdown -ww " ++ domid)
191207 case exitCode of
192208 ExitSuccess -> return ()
193- _ -> do xsWrite (xs_path ++ " /hvm-shutdown" ) " poweroff"
194- _ <- system_ (" xl trigger " ++ domid ++ " power" )
209+ _ -> do forkIO $ pushPowerButton uuid 3
195210 _ <- system_ (" xl shutdown -F -ww " ++ domid)
196211 return ()
197212 Nothing -> do system_ (" xl shutdown -c -ww " ++ domid)
0 commit comments