reboot indigo server (the whole MAC), an action script

Use this forum to discuss the Hue Lights plugin.
User avatar
kw123
Posts: 8420
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

reboot indigo server (the whole MAC), an action script

Post by kw123 »

Add this script to >>action group/ server action/ Execute Script<<

Then you can execute this action group eg with a schedule at eg 2am: your indigo server will gently shutdown (ie indigo will shutdown gracefully) and then reboot immediately

Use as you see fit.

Karl
ps this will also be part of the next utilities plug version

Code: Select all

#  Karl Wachs June 9, 2024
#  MIT license, use as you see fit, no warrenty what so ever
#
# this script will shutdown the indigo server and after xx secs, then reboot the mac
# set the wait time before rebot and the mac password
# set these parameters:
yourPassword = "xxxxx"	# the mac user id password, needed to issue "sudo -S" command
waitBeforeReboot = 15 	# this needs to be long enough to make sure indigo shuts down completely (just measure how long it takes for indigo to shutdown, add 3 secs to it)

import os, subprocess

# get indigo server proc pid
cmd = "ps -ef | grep 'MacOS/IndigoServer' | grep -v grep "
ret = str(subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0])

# py 3x/2x are diffirent:
if ret.find("b' ") > -1: # py3 binary return begins with a "b' "
	pid = ret.split()[2]
else:
	pid = ret.split()[1] # py2

# got all info   
indigo.server.log( "terminating indigo server pocess: {} then rebooting after {} secs".format(ret, waitBeforeReboot))

# now executing
try:
	pid = int(pid)
	# create shell file that will do the job, will be deleted at reboot by system, so no password visible after reboot
	f = open("/tmp/abc.sh","w")
	cmd = "kill -15 {} ;/bin/sleep {} ;echo '{}' | /usr/bin/sudo -S /sbin/shutdown -r now &".format(pid, waitBeforeReboot, yourPassword) # path to sudo etc must be included, as terminal opened this way does not find it in PATH
	f.write(cmd)
	f.close()

	# now executing stop indigo and the reboot
	#indigo.server.log("shutting down now with: {}".format(cmd))# can enabled, but then password is visible in logfile
	os.system("sh /tmp/abc.sh")
	return 
except Exception as e:
	indigo.server.log( "{}".format(e))
User avatar
Grognard
Posts: 56
Joined: Tue May 17, 2011 8:28 pm
Location: Seabrook, TX
Contact:

Re: reboot indigo server (the whole MAC), an action script

Post by Grognard »

I’m excited to try this out, I’ve been looking for/trying and failing to construct a script like this for a long time!
MarcoGT
Posts: 1111
Joined: Thu Sep 11, 2014 1:06 pm
Location: Germany

Re: reboot indigo server (the whole MAC), an action script

Post by MarcoGT »

Thanks Karl.

Well I do not think it is necessary to reboot the whole system every day.
I will keep it as emergency solution
User avatar
durosity
Posts: 4381
Joined: Thu May 10, 2012 3:21 pm
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: reboot indigo server (the whole MAC), an action script

Post by durosity »

This is handy, but do you think it could be amended to use the fdesetup authstart command so that it won’t prompt for a FileVault password on startup? I’ve tried modifying it with both that and using the -inputlist option to specify an xml document containing the password but to no avail. Any ideas?


Sent from my iPhone using Tapatalk Pro
Computer says no.
User avatar
kw123
Posts: 8420
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

Re: reboot indigo server (the whole MAC), an action script

Post by kw123 »

And this will shut down the INDIGO CLIENT only

Code: Select all

#  karl Wachs June 10 2024
#  MIT license, use as you see fit, no warrenty what so ever
#
# this script will stop the indigo CLIENT 

import os, subprocess

# get indigo server proc pid
cmd = "ps -ef | grep 'Contents/MacOS/Indigo ' | grep -v grep "
ret = str(subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0])

# py 3x/2x are diffirent:
if ret.find("b' ") > -1: # py3 binary return begins with a "b' "
	pid = ret.split()[2]
else:
	pid = ret.split()[1] # py2

# got all info   
indigo.server.log( "terminating indigo cleint pocess: {} ".format(ret))

# now executing
try:
	pid = int(pid)
	cmd = "kill -15 {} &".format(pid)
	# now executing stop indigo client
	indigo.server.log("shutting down client with: {}".format(cmd))
	os.system(cmd)
	return 
except Exception as e:
	indigo.server.log( "{}".format(e))
User avatar
kw123
Posts: 8420
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

Re: reboot indigo server (the whole MAC), an action script

Post by kw123 »

>>This is handy, but do you think it could be amended to use the fdesetup authstart command so that it won’t prompt for a FileVault password on startup? I’ve tried modifying it with both that and using the -inputlist option to specify an xml document containing the password but to no avail. Any ideas?<<

sorry none what so ever - i am not using fire fault.

The one posted will just (after indigo shutdown) do a "sudo shutdown -r now" with password piping

Karl

[edit]
may be this helps:
https://www.peachpit.com/articles/artic ... &seqNum=10
User avatar
kw123
Posts: 8420
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

Re: reboot indigo server (the whole MAC), an action script

Post by kw123 »

and as a one-liner in a shell

Code: Select all

/bin/kill -15 $(/bin/ps -ef | /usr/bin/grep "/IndigoServer" | /usr/bin/grep -v grep | /usr/bin/awk '{print $2}');/bin/sleep 15;/bin/echo 'yourpasswordhere' | /usr/bin/sudo -S /sbin/shutdown -r now
that will gracefully shutdown the indigo server app and then (after 15 secs) do a reboot
User avatar
kw123
Posts: 8420
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

Re: reboot indigo server (the whole MAC), an action script

Post by kw123 »

tried that one liner also in an iPhone shortcut and it works:

naturally you need to put in your users and passwords and ip number of your mac in the proper areas.

if not in your local network, start a vpn sessions first.

Karl
Attachments
Screenshot 2024-06-10 at 17.57.19.png
Screenshot 2024-06-10 at 17.57.19.png (200.48 KiB) Viewed 922 times
User avatar
durosity
Posts: 4381
Joined: Thu May 10, 2012 3:21 pm
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: reboot indigo server (the whole MAC), an action script

Post by durosity »

kw123 wrote:>>This is handy, but do you think it could be amended to use the fdesetup authstart command so that it won’t prompt for a FileVault password on startup? I’ve tried modifying it with both that and using the -inputlist option to specify an xml document containing the password but to no avail. Any ideas?<<

sorry none what so ever - i am not using fire fault.

The one posted will just (after indigo shutdown) do a "sudo shutdown -r now" with password piping

Karl

[edit]
may be this helps:
https://www.peachpit.com/articles/artic ... &seqNum=10
I will try having a play with it later on, alas it’s not the kind of thing I can just randomly play with, need to be in front of the server and also no wife in the house!


Sent from my iPhone using Tapatalk Pro
Computer says no.
Post Reply

Return to “Hue Lights”