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

Posted on
Sun Jun 09, 2024 9:46 am
kw123 offline
User avatar
Posts: 8401
Joined: May 12, 2013
Location: Dallas, TX

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

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))

Posted on
Sun Jun 09, 2024 1:59 pm
Grognard offline
User avatar
Posts: 54
Joined: May 17, 2011
Location: Seabrook, TX

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

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!

Posted on
Sun Jun 09, 2024 10:22 pm
MarcoGT offline
Posts: 1106
Joined: Sep 11, 2014
Location: Germany

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

Thanks Karl.

Well I do not think it is necessary to reboot the whole system every day.
I will keep it as emergency solution

Posted on
Mon Jun 10, 2024 2:18 am
durosity offline
User avatar
Posts: 4375
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

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

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.

Posted on
Mon Jun 10, 2024 4:51 am
kw123 offline
User avatar
Posts: 8401
Joined: May 12, 2013
Location: Dallas, TX

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

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))

Posted on
Mon Jun 10, 2024 4:54 am
kw123 offline
User avatar
Posts: 8401
Joined: May 12, 2013
Location: Dallas, TX

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

>>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/article.aspx?p=2300563&seqNum=10

Posted on
Mon Jun 10, 2024 5:55 am
kw123 offline
User avatar
Posts: 8401
Joined: May 12, 2013
Location: Dallas, TX

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

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

Posted on
Mon Jun 10, 2024 9:59 am
kw123 offline
User avatar
Posts: 8401
Joined: May 12, 2013
Location: Dallas, TX

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

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 192 times

Posted on
Mon Jun 10, 2024 10:59 am
durosity offline
User avatar
Posts: 4375
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

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

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/article.aspx?p=2300563&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.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest