Maddeen Posted August 23, 2020 Share Posted August 23, 2020 Hi everybody, just want to ask if theres a lightweight way to start / stop a vm. Maybe with a CLI command that can be packed within a automator script or an app or something more efficent? The way via webGUI is ok, but maybe there is an even more efficient way... because first you need to start the browser, than you have to login in unRAID and then you can start the VM. But imho there should be better way - similiar to WoL-Apps... yes, it`s also possible to fire up a wake on LAN package via CLI command running a CLI, loggin in and so on ... but a simple (double)click on an app-icon is even better Thanks for any hint. Have a nice sunday Quote Link to comment
testdasi Posted August 23, 2020 Share Posted August 23, 2020 The 4 virsh virsh start virsh reboot virsh shutdown virsh destroy --graceful shutdown / reboot may or may not work depending on client; hence, virsh destroy to kill the VM (--graceful to at least attempt to clear cache) 2 Quote Link to comment
Maddeen Posted August 23, 2020 Author Share Posted August 23, 2020 Thanks - works flawless. I`ll try to build a simple Automator script and give a feedback. Process should be very simple like.... open terminal app (hided) ssh into server virsh start <Name of VM> Quote Link to comment
JonathanM Posted August 23, 2020 Share Posted August 23, 2020 49 minutes ago, Maddeen said: Thanks - works flawless. I`ll try to build a simple Automator script and give a feedback. Process should be very simple like.... open terminal app (hided) ssh into server virsh start <Name of VM> The putty program includes a command line "plink" that does all that in one line. plink -pw <unraid root password> root@<unraid IP> virsh start <Name of VM> 1 Quote Link to comment
Maddeen Posted August 23, 2020 Author Share Posted August 23, 2020 (edited) @testdasiok - the commands themself works as predicted. But now I got another problem. Due that I'm a MacOS user I can't get "sshpass" to work. So I can't build a cli command like sshpass -p "password" ssh -o StrictHostKeyChecking=no root@YOUR_IP_ADRESS I need to have a passwordless login via ssh-key. Normally this wouldn't be a problem for me - I set this up on my Raspberry with no struggles - but on Raspberry it was quite easy. Copy pub-key to the PI - ready! But the manual I found HERE in the forum, is outdated (Unraid 6.8 and above does not allow executing scripts from the flash (/boot) drive) and nobody have updated this for a current solution Is it possible that I just copy the id_rsa.pub (generated on my mac) to the folder /boot/config/ssh/ - reboot - and everythings fine? UPDATE: @jonathanm - thanks for this hint. I dont saw it when I wrote the lines above. I'll try it and give a feedback asap UPDATE2: @jonathanm - sadly putty is a windows software and not be available for mac So the question above is still applies Edited August 23, 2020 by Maddeen Quote Link to comment
JonathanM Posted August 23, 2020 Share Posted August 23, 2020 52 minutes ago, Maddeen said: UPDATE2: @jonathanm - sadly putty is a windows software and not be available for mac I have it natively installed in linux, so not windows only. https://onvinetech.wordpress.com/2016/01/26/49/ Putty installation on mac, no clue if it includes plink, but it probably does since it looks like an adaptation of linux. 1 Quote Link to comment
Maddeen Posted August 25, 2020 Author Share Posted August 25, 2020 (edited) @jonathanm - thanks. The good news - I managed to install it. But know I need your assistance again hoping that the linux adaption is likely the macport. After installation I can run the command "putty" .. but it just opens the typical putty GUI (see Screen) But how about using the command plink as you described above? Edited August 25, 2020 by Maddeen Quote Link to comment
JonathanM Posted August 25, 2020 Share Posted August 25, 2020 10 minutes ago, Maddeen said: how about using the command plink as you described above? Does the plink file not exist in the same spot as putty? In the linux distribution, both files are put into /usr/bin In the windows version, putty.exe and plink.exe are both in the program files/putty folder. Not having a mac, I'm going to be of limited help here. 1 Quote Link to comment
Maddeen Posted August 25, 2020 Author Share Posted August 25, 2020 (edited) I got it ... just need to enter "plink" in the cli instead of "putty" - the typical ?help information appeared If I match your commands plink -pw <unraid root password> root@<unraid IP> virsh start <Name of VM> with my credentials .... magic happens Now I just need to find a way to wrap this command in an Automator script or a shortcut to start that command with a simple double click without seeing the terminal window appear Thanks again for you help. As soon as I got a solution I'll make a short summarized guide/documentation for other MacOS users out there Edited August 25, 2020 by Maddeen Quote Link to comment
leporel Posted May 5 Share Posted May 5 (edited) My approach, a simple program in golang. It can be run by a script at Unraid startup. ./vmhook 192.168.1.2:8151 windows10 At http://192.168.1.2:8151 there will be a “start” button, below is the code and the compiled version of the program. You can add other behavior or other buttons and build the program yourself. // Command to build program: // go build -trimpath -ldflags "-s -w" -o vmhook main.go package main import ( "fmt" "net/http" "os" "os/exec" ) func main() { if len(os.Args) < 3 { fmt.Println("Usage: ./vmhook <address>:<port> <VM_name>") return } addr := os.Args[1] vmName := os.Args[2] // Handler for the index page http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { // Serve a simple HTML page with a button html := ` <html> <head> <title>Start Windows10 VM</title> </head> <body> <form action="/start" method="post"> <input type="submit" value="Start"> </form> </body> </html> ` fmt.Fprintf(w, html) }) // Handler for the start button http.HandleFunc("/start", func(w http.ResponseWriter, r *http.Request) { // Execute the command "virsh start windows10" cmd := exec.Command("virsh", "start", vmName) err := cmd.Run() if err != nil { fmt.Fprintf(w, "Error starting VM: %v", err) return } fmt.Fprintf(w, vmName+" VM has been started successfully") }) // Start the HTTP server fmt.Printf("Server is starting on %s\n", addr) err := http.ListenAndServe(addr, nil) if err != nil { fmt.Printf("Server failed to start: %v\n", err) } } vmhook Edited May 5 by leporel Quote Link to comment
Craig Harris Posted August 28 Share Posted August 28 On 8/23/2020 at 9:40 AM, Maddeen said: @testdasiok - the commands themself works as predicted. But now I got another problem. Due that I'm a MacOS user I can't get "sshpass" to work. So I can't build a cli command like sshpass -p "password" ssh -o StrictHostKeyChecking=no root@YOUR_IP_ADRESS I need to have a passwordless login via ssh-key. Normally this wouldn't be a problem for me - I set this up on my Raspberry with no struggles - but on Raspberry it was quite easy. Copy pub-key to the PI - ready! But the manual I found HERE in the forum, is outdated (Unraid 6.8 and above does not allow executing scripts from the flash (/boot) drive) and nobody have updated this for a current solution Is it possible that I just copy the id_rsa.pub (generated on my mac) to the folder /boot/config/ssh/ - reboot - and everythings fine? UPDATE: @jonathanm - thanks for this hint. I dont saw it when I wrote the lines above. I'll try it and give a feedback asap UPDATE2: @jonathanm - sadly putty is a windows software and not be available for mac So the question above is still applies Sorry - very late to the party. To setup auto login with ssh keys I generally use : ssh-copy-id user@host Would that not work here? Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.