Script on boot

This is where you can find the latest ADM official release. Feel free to discuss any questions regarding it here.

Moderator: Lillian.W@AST

Post Reply
AndrewL
Posts: 1
youtube meble na wymiar Warszawa
Joined: Mon Feb 19, 2018 6:09 am

Script on boot

Post by AndrewL »

Hi,

I have a script I want to run in the background on my Asustor NAS. I have tried putting in as a crontab on "@reboot" and it start, and then I have tried putting it into "/volume0/usr/builtin/etc/init.d/"
"/volume0/usr/builtin/etc/script/" but neither worked, the file was deleted on reboot.

Is there someway to get the script to run on boot?
sksbir
Posts: 395
Joined: Tue Aug 25, 2015 9:23 pm

Re: Script on boot

Post by sksbir »

MikeG.6.5
Posts: 917
Joined: Fri May 15, 2015 1:56 am

Re: Script on boot

Post by MikeG.6.5 »

The OS that actually comes with our NASes is actually a modified form of Busybox, and not a real distribution of Linux.

As such the @reboot crontab job doesn't work at all. Nor does any of the officially documented Linux pathings. I still have an open ticket from almost 4 years ago about @reboot and it's not going to be closed any time soon... :( The link provided by @sksbir is the "official Asustor" method, which I also found to not be reliable enough to use on a production type of machine.

In order to get some of my scripts to run "on boot" I have them called every 15 minutes, with error checking to prevent something being double-executed. Look at this script for examples:

Code: Select all

#!/bin/sh
#######################################################################################
#  This script tests to make sure the PlexPy application is running on your Asustor   #
#  NAS.  if it is the script exits and does nothing.  If not it will restart PlexPy   #
#  as a daemon so the app is always running.  This app is usefull  #
#  because you can set it to monitor your HDD space, and view recently added shows    #
#  and movies within Plex.                                                            #
#  ---------------------------------------------------------------------------------  #
#  You can change this to test for remote access by changing the localhost to the     #
#  DNS name of your NAS.  Ex: If you use Asustor's DDNS service it would be something #
#  like http://yourddnsname.myasustor.com:  If you are using Maraschino on another    #
#  port than 7000 you will need to edit the script below to reflect the port number.  #
#  ---------------------------------------------------------------------------------  #
#  This can be used to test operation of any app that has a web page for accessing    #
#  the app itself.  If the app is a stand alone app and doesn't use a web page        #
#  this check will not work.  There are other ways to check their operations.         #
#  ---------------------------------------------------------------------------------  #
#  Visit http://forum.asustor.com/index.php and ask MikeG.6.5 for any support issues  #
#######################################################################################

curl -I -m 8 "http://10.1.20.40:xxxxx/home";
if [ "$?" -ne "0" ]

then
                /usr/sbin/syslog --log 0 --level 1 --user admin --event "PlexPy isn't running:  Starting it"                
                /volume1/misc/PlexPy/PlexPy.py -d
fi

#######################################################################################
#  Look for the file renderD128 and if it's not present, make a symlink to it in the  #
#  /dev/dri folder This file is required to make sure Plex can use HW Acceleration    #
#  for tranascoding jobs.  It may no longer be required, but I keep it in there,      #
#  just in case.                                                                      #
#######################################################################################

	ln -s /dev/renderD128 /dev/dri

#######################################################################################
#  This script tests to make sure the Ombi application is running on your Asustor NAS.#
#  If it is the script exits and does nothing.  If not it will restart Ombi as a      #
#  daemon so the app is always running.  This app is usefull because you can point    #
#  your users to this so they can request TV shows and movies to view on your Plex    #
#  server.  Ombi is tied to CouchPotato and Sonarr so searching and  downloading can  #
#  be done automatically after the show is approved.  (By you.)                       #
#  ---------------------------------------------------------------------------------  #
#  You can change this to test for remote access by changing the localhost to the     #
#  DNS name of your NAS.  Ex: If you use Asustor's DDNS service it would be something #
#  like http://yourddnsname.myasustor.com:  Remember you HAVE to put the port you     #
#  configure Ombi to run on in these scripts!                                         #
#  ---------------------------------------------------------------------------------  #
#  This can be used to test operation of any app that has a web page for accessing    #
#  the app itself.  If the app is a stand alone app and doesn't use a web page        #
#  this check will not work.  There are other ways to check their operations.         #
#  ---------------------------------------------------------------------------------  #
#  Visit http://forum.asustor.com/index.php and ask MikeG.6.5 for any support issues  #
#######################################################################################

curl -I -m 8 "localhost:3000/userlogin";
if [ "$?" -ne "0" ]

then
	for signal in "-15" "-1" "-9"
		do
  		pids=`ps -ef | grep Ombi `
#                echo killing Ombi
  		kill $signal $pids
#		echo Killed Ombi
	done

	/usr/sbin/syslog --log 0 --level 0 --user admin --event "PlexRequests isn't running: Starting it" 
	mono /volume1/misc/PlexRequests/Ombi.exe &
fi


exit 0
Look at the comments for descriptions of what each part does.

This is called by adding this line in the crontab: */15 * * * * /volume1/misc/ChkPlexPy.sh This is called every 15 minutes on the 15, so the longest period of time that none of these apps will not be running after a reboot is 15 minutes. It also checks that the apps themselves haven't crashed, and if they have any residual remnant processes kills them and then restarts the app. This is accomplished with the "for/do" loop in the last section of the script.

Any of the echos here are used if I run the script in a PuTTY terminal window. (They don't have any output when executed via the crontab. The syslog lines write to the system logs if the app needs to be restarted.)

This is the only way I've found to ensure that these apps will always be running.
Post Reply

Return to “[Official] For AS-60X Series”