Restart-Computer performs shutdown on Ubuntu 18.04
See original GitHub issueSteps to reproduce
Restart-Computer
Expected behavior
The computer should restart.
Actual behavior
The computer is shut down.
PS /home/adminjer> Restart-Computer
Shutdown scheduled for Sun 2021-01-31 20:10:52 UTC, use 'shutdown -c' to cancel.
PS /home/adminjer> Connection to ubnt-az-01 closed by remote host.
Connection to ubnt-az-01 closed.
The computer running into this issue on is running in Azure, where the platform logs stated the following after finding that the VM was in a Stopped state:
"properties": {
"title": "Stopped by user or process",
"details": "This virtual machine is stopping as requested by an authorized user or by a process running inside the virtual machine.",
"currentHealthStatus": "Available",
"previousHealthStatus": "Available",
"type": "Downtime",
"cause": "UserInitiated"
}
Environment data
PSVersion 7.1.1
PSEdition Core
GitCommitId 7.1.1
OS Linux 5.4.0-1039-azure #41~18.04.1-Ubuntu SMP Mon Jan 18 14:00:01 UTC 2021
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
I have not tested whether the issue is also present on other Linux distros, but I would suspect so.
I haven’t looked very closely at the source code, but what is supposed to happen seems correct: https://github.com/PowerShell/PowerShell/blob/master/src/Microsoft.PowerShell.Commands.Management/commands/management/ComputerUnix.cs#L45
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Restart-Computer performs shutdown on Ubuntu 18.04
Restart-Computer performs shutdown on Ubuntu 18.04 #18325 · Summary ...
Read more >Ubuntu 18.04 stuck at shutdown
Go to Settings > Power then turn off all Automatic Suspend options. Also choose Blank screen to Never . Till Ubuntu team will...
Read more >Running commands on shutdown/restart Ubuntu 18.04
I created a executable file in /etc/NetworkManager/dispatcher.d/01firewall No result. · I created a service in /lib/systemd/system/ with : [Unit] ...
Read more >How to Restart Windows Server 2016 - Reboot Commands
Step 2: Restart the System. In the PowerShell window, type the following command and press Enter: Restart-Computer. By default, you'll get ...
Read more >How to reboot or shut down your virtual machine?
sudo shutdown -r now This will perform a system shutdown in a proper way and then reboot the computer. sudo init 6. To...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Found the problem. It’s with the PowerShell code, not Ubuntu. Essentially, the
-r now
arguments for a restart are being ignored, resulting in a shutdown.In PowerShell/src/Microsoft.PowerShell.Commands.Management/commands/management/ComputerUnix.cs
Restart-Computer
ultimately invokesRunCommand("/sbin/shutdown", "-r now");
RunCommand
has two errors in it. It does not respect either input (command
orargs
)Filename
is hard-coded to"/sbin/shutdown"
Arguments
is set to an empty string.command
andargs
are ignored entirely.Created a PR but I am new at contributing to public repos and do not have experience with builds or testing for validation. Perhaps someone more experienced could validate the code.