56

we have android + linux m/c, we log in into linux shell and boot the machine in android GUI. now we have the some script that is running on the same machine through linux shell. In that case when the script hangs we need to restart android machine. but it result into restarting the linux machine too. as they are on same machine. so i need the way to restart the android so it comes out of hang state and control remains on the script that is running through the linux shell.

so is there any adb or linux command that work for me?

Sagar
  • 2,315
  • 7
  • 25
  • 34

4 Answers4

159

Have you tried simply 'reboot' with adb?

  adb reboot

Also you can run complete shell scripts (e.g. to reboot your emulator) via adb:

 adb shell <command>

The official docs can be found here.

alex
  • 5,516
  • 2
  • 36
  • 60
  • read my question carefully...when i do adb reboot android and linux machine both gets rebooted as they are on same machine. i want to restart the android machine but not linux shell . – Sagar Aug 06 '13 at 09:25
  • Yes i understood that, but my example above shows, how to send the reboot command to the instance of android on your machine. I thought, the android machine runs as vm in a emulator, or do you mean, that android is running natively? on what machine. please decribe your issue more specific then. Android does run on arm machines but not on x86 (natively), so your android instance is in an emulator, doesn't it? – alex Aug 06 '13 at 11:26
  • no it is running natively. and android runs natively on x86 m/c too. i have android + linux machine. right now booted in android. i log in through xshell to that machines linux shell. i run some script through that shell wihch communicate with android. when i detect that android is hanged then i want to reboot the system but when i reboot the system it eventually reboot the linux too. i dnt want to reboot linux because script is running through linx shell. – Sagar Aug 06 '13 at 12:51
  • Ok, what i don't get is how you have linux and android running. Following your explanation you have two operating systems on a machine, android and linux. how do you do that? Is there a virtual machine? – alex Aug 06 '13 at 13:02
  • And what do mean by "linux m/c" ? – alex Aug 06 '13 at 13:04
  • i have one machine. on which both linux and android installed.i boot that machine into android and side by side from second machine i use xshell tool to login into linux shell of 1 st machine on which android is booted. – Sagar Aug 06 '13 at 13:21
  • Yes thats clear but how can you run a linux and an Android linux os at the same time on the same machine without a virtualization like emulator, virtual box or something else? – alex Aug 06 '13 at 13:23
  • do u have any idea about xshell tool? – Sagar Aug 06 '13 at 13:25
  • I boot system only in 1 os i.e android and use xshell to login linux shell.. i think this is enough. – Sagar Aug 06 '13 at 13:28
  • But then adb reboot reboots the client machine and the android machine?? – alex Aug 06 '13 at 13:41
  • Unfortunately i am not familiar with xshell. But it should definetly work if you avctivate ADB in Android and then connect via adb from the client machine – alex Aug 06 '13 at 14:29
38

You can reboot the device by sending the following broadcast:

$ adb shell am broadcast -a android.intent.action.BOOT_COMPLETED

drindt
  • 901
  • 10
  • 15
  • Rebooted the device but cmd is stuck at "Broadcasting: Intent { act=android.intent.action.BOOT_COMPLETED }" , so i don't think its a complete solution. – sak Mar 21 '18 at 05:12
  • 2
    Unfortunately it won't work due to permissions. @alex answer should be marked as correct – Pietrek Jun 19 '20 at 12:21
24

adb reboot should not reboot your linux box.

But in any case, you can redirect the command to a specific adb device using adb -s <device_id> command , where

Device ID can be obtained from the command adb devices
command in this case is reboot

anishsane
  • 20,270
  • 5
  • 40
  • 73
0

I think the only way to do this is to run another machine in parallel and use that machine to issue commands to your android box similar to how you would with a phone. If you have issues with the IP changing you can reserve an ip on your router and have the machine grab that one instead of asking the routers DHCP for one. This way you can ping the machine and figure out if it's done rebooting to continue the script.

ZeroInputCtrl
  • 169
  • 1
  • 8