Page 1 of 4

[HOW TO] Run your own script on system startup

Posted: Fri Mar 15, 2013 1:57 pm
by Steve@AST
You can follow the the steps below to run the demon on system startup

1. login NAS as "root" via ssh client (e.g. Utility like "Putty" on Windows or "terminal" on Mac)

2. Put your script under /usr/local/etc/init.d/

3. Rename script name to SXXscript_name (S00 ~ S99: script execute order, S00 is in order of first, S99 is in order of last)

e.g.

Code: Select all

# mv /usr/local/etc/init.d/first_autorun.sh /usr/local/etc/init.d/S00first
# mv /usr/local/etc/init.d/last_autorun.py /usr/local/etc/init.d/S99last

4. Modify execute permission for this script

e.g.

Code: Select all

# chmod +x /usr/local/etc/init.d/S00first 
# chmod +x /usr/local/etc/init.d/S99last

5. You can try to execute this script, and check result

e.g.

Code: Select all

# /usr/local/etc/init.d/S01autorun

6. After system restart, your script should be run automatically

Re: [HOWTO] Run your demon when system startup

Posted: Fri Mar 15, 2013 5:29 pm
by ho66es
Nicely done! could be very handy indeed

Re: [HOW TO] Run your own script on system startup

Posted: Fri Jul 19, 2013 1:11 pm
by Gunthor
Somehow my script (S60NASsleep.sh) won't start on its own when the machine powers up. Please assist. The two other files within the init.d folder (NAShddstatus and NASsleepLog) are files the script is using:

Code: Select all

login as: root
root@192.168.XXX.XXX's password:
# cd ../usr/local/etc/init.d
# ls -l
total 12
[...]
-rw-r--r--    1 root     root            41 Jul 19 00:14 NAShddstatus
-rw-r--r--    1 root     root           851 Jul 19 00:14 NASsleepLog
[...]
-rwxr-xr-x    1 root     root          1368 Jul 18 21:24 S60NASsleep.sh
[...]
#
Running the script manually

Code: Select all

./S60NASsleep.sh
works as expected

Re: [HOW TO] Run your own script on system startup

Posted: Sun Dec 22, 2013 4:39 pm
by wolferich
Can someone post a script to autostart XBMC ?

Re: [HOW TO] Run your own script on system startup

Posted: Tue Dec 31, 2013 6:44 am
by phantasmnz
Gunthor wrote:Somehow my script (S60NASsleep.sh) won't start on its own when the machine powers up. Please assist. The two other files within the init.d folder (NAShddstatus and NASsleepLog) are files the script is using:

Code: Select all

login as: root
root@192.168.XXX.XXX's password:
# cd ../usr/local/etc/init.d
# ls -l
total 12
[...]
-rw-r--r--    1 root     root            41 Jul 19 00:14 NAShddstatus
-rw-r--r--    1 root     root           851 Jul 19 00:14 NASsleepLog
[...]
-rwxr-xr-x    1 root     root          1368 Jul 18 21:24 S60NASsleep.sh
[...]
#
Running the script manually

Code: Select all

./S60NASsleep.sh
works as expected

Have you tried renaming your script without the .sh suffix? I just added a custom script and it worked just great.

Related question - the files in /etc get rebuilt each boot - does anyone know how? My custom script is simply a mount command, I would love to add directlu to /etc/fstab but this gets replaced every boot time. I am basically using this to access data from a pre-existing disk without having to wipe it.

Re: [HOW TO] Run your own script on system startup

Posted: Sun Jan 05, 2014 1:00 am
by glide
phantasmnz wrote: ...

Related question - the files in /etc get rebuilt each boot - does anyone know how? My custom script is simply a mount command, I would love to add directlu to /etc/fstab but this gets replaced every boot time. I am basically using this to access data from a pre-existing disk without having to wipe it.
Where are you keeping the file? In /etc or /usr/local/etc ? I guess you need to keep in /usr/local/etc/init.d (as stated in the first post).

Re: [HOW TO] Run your own script on system startup

Posted: Sun Jan 05, 2014 4:23 am
by phantasmnz
I can't find a location where a new fstab will load - I guess I could add a script to overwrite /etc/fstab with a new one and run mount -a but that's not much different to what I'm already doing (a manual mount command)


Sent from my iPhone using Tapatalk

Re: [HOW TO] Run your own script on system startup

Posted: Sun Jan 05, 2014 4:54 am
by glide
To be honest, I don't see a reason not to use custom script to mount a drive... It's not any different from what fstab does anyway.
I wouldn't edit existing fstab if I was you (there is no benefit what so ever). The way you are doing it right now, is just fine.

If it is working for you the way the way it is right now... don't fuck the running system ;)

Re: [HOW TO] Run your own script on system startup

Posted: Sun Jan 05, 2014 5:15 am
by phantasmnz
I guess I agree - it was just annoying me that I couldn't work out what was overwriting it each boot. To be fair - I guess if I had to support it, I'd want the critical files to be as untamperable as possible too.


Sent from my iPhone using Tapatalk

Re: [HOW TO] Run your own script on system startup

Posted: Sat Feb 08, 2014 10:12 am
by callifo
Great thanks