Page 1 of 1

action to reboot / shutdown server

PostPosted: Sun Nov 25, 2018 7:15 pm
by kw123
put this into an action / server / execute script :
Code: Select all
import os
myPassword = "put my password here"

# for reboot:
cmd = "/sbin/reboot"

# for shutdown
#cmd = "/sbin/shutdown now"

os.system("echo '"+ myPassword + "' | sudo -S "+cmd+" &")

when executed the mac indigo server will reboot or will shut down depending on the option chosen.

Karl

Re: action to reboot / shutdown server

PostPosted: Mon Nov 26, 2018 1:06 am
by howartp
Awesome!


Sent from my iPhone using Tapatalk Pro

Re: action to reboot / shutdown server

PostPosted: Mon Nov 26, 2018 11:56 am
by Colorado4Wheeler
Mac Commander also does this as well as lets you run anything on a remote Mac.

Re: action to reboot / shutdown server

PostPosted: Tue Nov 27, 2018 10:53 am
by kw123
@Colorado4Wheeler.. downloaded your plugin.. how would you use it to reboot / shutdown the server. I do see sleep, stop/start apps.
one thing I really would like to to do is to stop a plugin wait and then restart it, not the reload action of indigo.
I did a "tell system ... move , pick .." but that depends on plugin position in the menu ..
Indigo does not expose a lot of properties to apple script (and will likely not add any) so that a direct command is not available.

thanks

Karl
ps looking at your plugin code inspires me to try a lot of new things.

action to reboot / shutdown server

PostPosted: Tue Jul 13, 2021 9:59 am
by kw123
To make indigo self recover after power failures, hanging of server ..
3 tools:
  1. wake on lan
    on an raspberry pi:
    wakeonlan mac#OfIndigoEthernetCard
    - pibeacon can be set to do that: edit pi-server and add the mac# in the wake on .. field
    you need to enable wake on lan on the Mac in: System prefs/energy saver/ "wake for network access"
    this only works when the mac is asleep not when it is shutdown
  2. switchbot bot attached to the MAC, that switch can be remotely operated (pibeacon) to shutdown or restart the power on the mac (https://forums.indigodomo.com/viewtopic.php?f=187&t=25391&p=204194#p204194
  3. run a script on the indigo server that pings the nearest switch, if no success reboot, see below

Code: Select all
# karl wachs 2021-07-14, use as you see fit
# put this script into the action server script  of a schedule, run it once per minute
# this script should run every minute. It will check if at least ONE ping to x different ip numbers works
# if ok exit, set lastNetworkOKTest to current time stamp
# if not ok check if last ok test is older than 3 minutes ( give eg switches time to reboot during upgrades etc )
#   if lastOKtest < 3  minutes ago: exit
#   if lastreboot < 15 minutes ago: exit
#   reboot
# you need to set password  below
# make sure that execution time stays below 10 secs (max # of ip numbers to test = 3)
#   ==> max time is 2 rounds of pings for each ip = 2*3 secs + 2 secs wait = 8 secs
#  it will create all necessary variables and folder
# all the variables usedshow time since epoch not at datestring
#
import time
import subprocess

testMaxEvery         = 1.*59
rebootIfOkTestOlderThan   = 3.*60
rebootNotMoreOftenThan   = 20.*60
pwd                  = "your mac password here "
ipnumbersForPingTest   = ["192.168.1.10","192.168.1.1","192.168.1.2"]# use 1..3 ip numbers
numberOfPings         = 2
logOK               = True
logFailed            = True

try:     indigo.variables.folder.create(u"rebootIfNoNetwork")
except: pass

try:     indigo.variable.create(u"lastNetworkTest", "0","rebootIfNoNetwork")
except:  pass
try:     lastNetworkTest = float(indigo.variables["lastNetworkTest"].value)
except: lastNetworkTest = 0

try:     indigo.variable.create(u"lastOKNetworkTest", "0","rebootIfNoNetwork")
except: pass
try:     lastNetworkOKTest = float(indigo.variables["lastNetworkOKTest"].value)
except: lastNetworkOKTest = 0

try:     indigo.variable.create(u"lastReboot", "0","rebootIfNoNetwork")
except: pass
try:     lastReboot = float(indigo.variables["lastReboot"].value)
except: lastReboot = 0

now = time.time()
if now - lastNetworkTest < testMaxEvery: exit()
indigo.variable.updateValue(u"lastNetworkTest", str(now))

# send  ping tries
for ipN in ipnumbersForPingTest:
   pingCmd= "/sbin/ping -c {} -W 1 {}".format(numberOfPings , ipN)
   ret = subprocess.Popen(pingCmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
   if logOK: indigo.server.log(">>reboot if no network<< testing: {}".format(pingCmd))
   if ret.find("100.0% packet loss") == -1:  # accept at least one ping ok
      if logOK: indigo.server.log(">>reboot if no network<<: test passed ")
      indigo.variable.updateValue(u"lastOKNetworkTest", str(now))
      exit()

if now - lastNetworkOKTest < rebootIfOkTestOlderThan:
   if logFailed: indigo.server.log(">>reboot if no network<< test failed, but delaying reboot for {:.0f} secs, waiting for next check".format(rebootIfOkTestOlderThan-(now - lastNetworkOKTest)))
   exit()

if now - lastReboot < rebootNotMoreOftenThan:
   if logFailed: indigo.server.log(">>reboot if no network<< test failed, but delaying reboot for {:.0f} secs, last reboot was done previuosly".format(rebootNotMoreOftenThan-(now - lastReboot)))
   exit()

indigo.variable.updateValue(u"lastReboot", str(now))

if logFailed: indigo.server.log(">>reboot if no network<< failed, rebooting in 2 secs")
time.sleep(2)
cmd = u"echo '"+ pwd + u"' | sudo -S /sbin/reboot now"
subprocess.Popen(cmd, shell=True)

action to reboot / shutdown server

PostPosted: Wed Jul 14, 2021 1:06 pm
by kw123
and one more option, if you loose power and power back in is not to long into the future, you can set the mac to power on 3 hours from now, run it every 10 minutes.
So if the power to your mac comes back with the next 3 hours, it will power on, if it is later, it will wait 3+24 hours, better than nothing.

Code: Select all
# karl wachs 2021-07-14, use as you see fit
# put this script into the action server script  of a schedule, run it once per minute
#  it will then use pmset to set "poweron "to current time + 3 hours, it is only active when MAC is off, when MAC runs nothing happens
import datetime
import subprocess
pwd = "your mac password"

newBootHour =  datetime.datetime.now() + datetime.timedelta(hours = 3)
boottime = "{:02d}:{:02d}:00".format(newBootHour.hour,newBootHour.minute)
indigo.server.log(">>setting boot time << {}".format(boottime) )

cmd = u"/bin/echo '"+ pwd + "' | /usr/bin/sudo -S /usr/bin/pmset repeat wakeorpoweron MTWRFSU " +boottime

#indigo.server.log(">>setting boot time << {}".format(cmd) )
ret = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
u

Re: action to reboot / shutdown server

PostPosted: Fri Sep 23, 2022 6:08 am
by Bildhauer
I'm not sure if this is the correct context but I try.

I have an Automator app which quits and and 10 seconds will start the indigo server again. But how can I call/ start this app?

Thanks in advance for your help!

Re: action to reboot / shutdown server

PostPosted: Fri Sep 23, 2022 7:53 am
by Different Computers
Closest thing I can think of is to have the Quit automation do a periodic test for a response from Indigo, and to NOT proceed if Indigo responds.

Re: action to reboot / shutdown server

PostPosted: Fri Sep 23, 2022 10:32 am
by Bildhauer
If the last entry is dedicated ,my post:

The only thing I'm looking for is a way to start this external App which is located on my desktop.

I think it's very ieasy but I cannot find a way to start it.

Re: action to reboot / shutdown server

PostPosted: Sat Sep 24, 2022 4:13 am
by Bildhauer
Just found a solution to my issue:

Code: Select all
import os
path = "/Applications/Safari.app"
os.system(f"open {path}")