[HOW TO] Run your own script on system startup

Share your awesome tips and tricks here.

Moderator: Lillian.W@AST

User avatar
Steve@AST
Posts: 150
youtube meble na wymiar Warszawa
Joined: Tue Jun 05, 2012 4:20 pm

[HOW TO] Run your own script on system startup

Post 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
ASUSTOR AS-602T
MacBook Air
iPhone 4s, New iPad, iPod nano
ho66es
Posts: 476
Joined: Wed Mar 13, 2013 5:38 am

Re: [HOWTO] Run your demon when system startup

Post by ho66es »

Nicely done! could be very handy indeed
608t
User avatar
Gunthor
Posts: 116
Joined: Sun Jun 23, 2013 6:04 pm
Location: Germany - Stuttgart

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

Post 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
Since 07/2023: Asustor AS6702T, (2 x Seagate IronWolf 12TB, RAID 1)
Old: Asustor AS-604RS, ADM 3.1.2.RHG1 (4 x WD Red WD30EFRX 3TB, RAID 5)
wolferich
Posts: 79
Joined: Wed Nov 27, 2013 10:24 pm

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

Post by wolferich »

Can someone post a script to autostart XBMC ?
phantasmnz
Posts: 54
Joined: Tue Dec 31, 2013 6:40 am

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

Post 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.
glide
Posts: 20
Joined: Sun Dec 22, 2013 7:27 am

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

Post 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).
AS-204TE
phantasmnz
Posts: 54
Joined: Tue Dec 31, 2013 6:40 am

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

Post 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
glide
Posts: 20
Joined: Sun Dec 22, 2013 7:27 am

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

Post 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 ;)
AS-204TE
phantasmnz
Posts: 54
Joined: Tue Dec 31, 2013 6:40 am

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

Post 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
callifo
Posts: 49
Joined: Thu Feb 06, 2014 6:51 pm

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

Post by callifo »

Great thanks
Post Reply

Return to “Tips & Tricks”