It is currently Sun Aug 25, 2019 11:17 pm
All times are UTC + 8 hours

[HOW TO] Run your own script on system startup

Share your awesome tips and tricks here.

[HOW TO] Run your own script on system startup

Postby Steve@AST » Fri Mar 15, 2013 1:57 pm

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
User avatar
Steve@AST
 
Posts: 150
Joined: Tue Jun 05, 2012 4:20 pm

Re: [HOWTO] Run your demon when system startup

Postby ho66es » Fri Mar 15, 2013 5:29 pm

Nicely done! could be very handy indeed
608t
ho66es
 
Posts: 476
Joined: Wed Mar 13, 2013 5:38 am

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

Postby Gunthor » Fri Jul 19, 2013 1:11 pm

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
Asustor AS-604RS, ADM 3.1.2.RHG1 (4 x WD Red WD30EFRX 3TB, RAID 5)
User avatar
Gunthor
 
Posts: 107
Joined: Sun Jun 23, 2013 6:04 pm
Location: Germany - Stuttgart

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

Postby wolferich » Sun Dec 22, 2013 4:39 pm

Can someone post a script to autostart XBMC ?
wolferich
 
Posts: 52
Joined: Wed Nov 27, 2013 10:24 pm

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

Postby phantasmnz » Tue Dec 31, 2013 6:44 am

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

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

Postby glide » Sun Jan 05, 2014 1:00 am

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

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

Postby phantasmnz » Sun Jan 05, 2014 4:23 am

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
phantasmnz
 
Posts: 54
Joined: Tue Dec 31, 2013 6:40 am

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

Postby glide » Sun Jan 05, 2014 4:54 am

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

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

Postby phantasmnz » Sun Jan 05, 2014 5:15 am

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
phantasmnz
 
Posts: 54
Joined: Tue Dec 31, 2013 6:40 am

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

Postby callifo » Sat Feb 08, 2014 10:12 am

Great thanks
callifo
 
Posts: 47
Joined: Thu Feb 06, 2014 6:51 pm

Next

Return to Tips & Tricks

  • You cannot post new topics in this forum
    You cannot reply to topics in this forum
    You cannot edit your posts in this forum
    You cannot delete your posts in this forum
    You cannot post attachments in this forum
  • Who is online

    Users browsing this forum: No registered users and 1 guest