action to reboot / shutdown server

Posted on
Sun Nov 25, 2018 7:15 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

action to reboot / shutdown server

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
Attachments
Screen Shot 2018-11-25 at 19.14.02.png
Screen Shot 2018-11-25 at 19.14.02.png (45.37 KiB) Viewed 10897 times

Posted on
Mon Nov 26, 2018 1:06 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: action to reboot / shutdown server

Awesome!


Sent from my iPhone using Tapatalk Pro

Posted on
Mon Nov 26, 2018 11:56 am
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: action to reboot / shutdown server

Mac Commander also does this as well as lets you run anything on a remote Mac.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Tue Nov 27, 2018 10:53 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: action to reboot / shutdown server

@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.
Attachments
Screen Shot 2018-11-27 at 10.49.22.png
Screen Shot 2018-11-27 at 10.49.22.png (21.03 KiB) Viewed 10775 times

Posted on
Tue Jul 13, 2021 9:59 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

action to reboot / shutdown server

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)

Posted on
Wed Jul 14, 2021 1:06 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

action to reboot / shutdown server

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

Posted on
Fri Sep 23, 2022 6:08 am
Bildhauer offline
Posts: 160
Joined: Sep 30, 2019
Location: 22113 Oststeinbek (near Hamburg), Germany

Re: action to reboot / shutdown server

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!

Posted on
Fri Sep 23, 2022 7:53 am
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: action to reboot / shutdown server

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.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Fri Sep 23, 2022 10:32 am
Bildhauer offline
Posts: 160
Joined: Sep 30, 2019
Location: 22113 Oststeinbek (near Hamburg), Germany

Re: action to reboot / shutdown server

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.

Posted on
Sat Sep 24, 2022 4:13 am
Bildhauer offline
Posts: 160
Joined: Sep 30, 2019
Location: 22113 Oststeinbek (near Hamburg), Germany

Re: action to reboot / shutdown server

Just found a solution to my issue:

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

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests

cron