Autostart script

Questions that don't fit in any category below may go here
Forum rules
1) This is a user forum for Synology users to share experience/help out each other: if you need direct assistance from the Synology technical support team, please use the following form:

https://account.synology.com/support/support_form.php?lang=enu



2) To avoid putting users' DiskStation at risk, please don't paste links to any patches provided by our Support team as we will systematically remove them. Our Support team will provide the correct patch for your DiskStation model.
jayme
I'm New!
I'm New!
Posts: 6
Joined: Sun Feb 27, 2011 6:36 am

Autostart script

Postby jayme » Mon Jul 18, 2011 1:15 am

I know there are many questions about this, on the forum, however no answer has worked out for me so far which is why I've decided to post as well.

I have a Synology NAS DS710+.
I have created a shared folder called "winhd" which I use as a "Windows HD emulation".
In this folder I've created a few sub-folders: documents, music, transmission, web.

Then, I have run "mount --bind" on the folders which these should be linked to. I've made a script like this:

bind_winhd.sh

Code: Select all

#! /bin/sh
#
mount /volume1/transmission /volume1/winhd/transmission --bind
mount /volume1/homes/my_user /volume1/winhd/documents --bind
mount /volume1/music /volume1/winhd/music --bind
mount /volume1/web /volume1/winhd/web --bind


if I run this script via ssh, like "sh bind_winhd.sh" it does the magic. Now, I can access all these folders from within my "winhd" folder which I've added as a network drive on my Windows PC "(Z:)". All good!

However, if I restart my NAS I have to run the script again. The folders don't remain "mounted", so to say.

So. The solution, I suppose, would be to make this script autorun; when the NAS powers on, the script runs.

Now, as I said, I've seen plenty of posts on how to achieve this but I can't get it to work.
I tried putting my script in /usr/local/etc/rc.d/ -- didn't work.
I tried putting my script in /usr/syno/etc/rc.d/ -- that didn't work either.

chmod like so:

Code: Select all

DiskStation> chmod +rwx bind_winhd.sh
DiskStation> ls -l bind_winhd.sh
-rwxr-xr-x    1 root     root           227 Jul 18 02:08 bind_winhd.sh


...so I assume there shouldn't be a problem with the persmissions. Still, it doesn't run on start-up!

Anyone has an idea?

Thanks!
J
User avatar
maxxfi
Compiler
Compiler
Posts: 6794
Joined: Sun Dec 27, 2009 12:13 pm
Location: Espoo, Finland

Re: Autostart script

Postby maxxfi » Mon Jul 18, 2011 5:13 pm

Try to put the commands inside /etc/rc.local file
(create the file if it doesn't exist)
No longer using Synology NAS, moved to more open source solutions.
DS-106j > DS-210j > DS-411
User avatar
HarryPotter
Honorary Moderator
Honorary Moderator
Posts: 19251
Joined: Mon Oct 23, 2006 12:48 pm
Location: Switzerland

Re: Autostart script

Postby HarryPotter » Mon Jul 18, 2011 5:27 pm

/usr/syno/etc/rc.d is the correct place.

Not sure, but I think the naming of the file is the problem. It should start with Sxx, for example S99bind_winhd.sh or similar.
*Please do not Private Message me for support questions; leave it on the forum so all members can learn. Thanks!*

DS718+ / DSM 6.2-23511 / ST4000VN000-2AH166 / SA400S37120G SSD cache /16 GB RAM
DS415+ / DSM 6.2-23511

LMS 7.9.1-166, 2 Squeezebox 3 + Boom

APC Smart UPS SUA750i
ThExSenatoR
Trainee
Trainee
Posts: 17
Joined: Sat Jun 11, 2011 11:41 am

Re: Autostart script

Postby ThExSenatoR » Mon Jul 18, 2011 6:46 pm

The correct place is: /usr/local/etc/rc.d
You can use any name for your script.

Dont forget to set permissions for your script:
chmod 700 <your_script_name>

Reboot your DS and your script should be auto executed. It's working this way on my DS.
DS1511+ * 5x2TB Samsung HD204UI Raid5 * LACP Enabled
jayme
I'm New!
I'm New!
Posts: 6
Joined: Sun Feb 27, 2011 6:36 am

Re: Autostart script

Postby jayme » Tue Jul 19, 2011 3:50 am

Thanks you all very much for replying!
Now I've tested all the sugested alternatives.


HarryPotter wrote:/usr/syno/etc/rc.d is the correct place.

Not sure, but I think the naming of the file is the problem. It should start with Sxx, for example S99bind_winhd.sh or similar.

Unfortunately this didn't work. I renamed my file accordingly, and made sure the right permissions were set - still no result.

ThExSenatoR wrote:The correct place is: /usr/local/etc/rc.d
You can use any name for your script.

Dont forget to set permissions for your script:
chmod 700 <your_script_name>

Reboot your DS and your script should be auto executed. It's working this way on my DS.

This didn't work for me either. I find it strange, because in both the above mentioned paths I find other files which I assume autorun on start-up. Alas, I had no luck.

maxxfi wrote:Try to put the commands inside /etc/rc.local file
(create the file if it doesn't exist)

This one did the trick! Thank you!

I added my file to execute within this file, like so:

Code: Select all

#!/bin/sh

# Optware setup
[ -x /etc/rc.optware ] && /etc/rc.optware start

sh /path/to/my/file/script.sh

exit 0


After this was done, I realized if I want to autorun other scripts on start-up it would be more convenient to actually have a folder from which every script within will autorun. So, I put together a small script for this purpose. Maybe there are others out there who can't get anything else to work, who might find this useful, if so, here you go:

autorun.sh

Code: Select all

#! /bin/sh
# Autorun script.
#
# Usage instructions:
# ===============================================================
#  1. Put this script-file anywhere convenient,
#     e.g. "/volume1/homes/your_username/autorun"
#
#  2. Within above mentioned folder, create a subfolder,
#     e.g. "/volume1/homes/your_username/autorun/sh" (this is your so called "autorun folder")
#     IMPORTANT: Do not use the same path as in (1), you MUST use a subfolder (or any other DIFFERENT path)
#
#  3. Open and edit the '/etc/rc.local file' to add execution of this script, like so:
#     sh /volume1/homes/your_username/autorun/autorun.sh #(change to your path)
#
#  After you've finised the above steps you can put any *.sh file in your
#  "autorun folder", and they will automatically run when your NAS boots.
#
#  NOTE:
#  This script creates a logfile where you can see if things are working properly.
#  Please don't forget to edit the paths bellow to correspond to your own paths.


# Path settings:
# ===============================================================

# Path to "autorun folder":
var_autorunDir="/volume1/homes/your_username/autorun/sh"

# Path to logfile:
var_logFile="/volume1/homes/your_username/autorun/autorun.log"

# ===============================================================

# Function fn_CurrTime - Display current time as: YYYY-MM-DD hh:mm:ss
fn_CurrTime() { echo $(date +%Y-%m-%d\ %H:%M:%S); }

# Write to logfile on script execution:
echo "($(fn_CurrTime)) $0 executed successfully" >> $var_logFile

# Look for *.sh files, and count them:
var_shFiles=$(ls "$var_autorunDir"/*.sh 2> /dev/null | wc -l)
if [ "$var_shFiles" != "0" ]; then

   # If *.sh files found are >= 1, then:
   
   # Write to log file:
   echo "($(fn_CurrTime)) $var_shFiles *.sh file(s) found and executed:" >> $var_logFile

   # Execute every *.sh file in the folder defined by var_autorunDir:
   for file in "$var_autorunDir"/*.sh
   do
      # Write to logfile:
      echo "  > $file" >> $var_logFile
      
      # Execute script(s):
      sh "$file"
   done
   
else
   # If no *.sh files are found, write to logfile:
   echo "($(fn_CurrTime)) no ($var_shFiles) *.sh files were found." >> $var_logFile
fi

# Write to logfile on script exit:
echo -e "($(fn_CurrTime)) $0 exit\n" >> $var_logFile
exit
J
User avatar
HarryPotter
Honorary Moderator
Honorary Moderator
Posts: 19251
Joined: Mon Oct 23, 2006 12:48 pm
Location: Switzerland

Re: Autostart script

Postby HarryPotter » Tue Jul 19, 2011 9:07 am

Dont know why it doesnt work for you. My mount script is doing its job on /usr/syno/etc/rc.d without any issues.
*Please do not Private Message me for support questions; leave it on the forum so all members can learn. Thanks!*

DS718+ / DSM 6.2-23511 / ST4000VN000-2AH166 / SA400S37120G SSD cache /16 GB RAM
DS415+ / DSM 6.2-23511

LMS 7.9.1-166, 2 Squeezebox 3 + Boom

APC Smart UPS SUA750i
afawaz
Beginner
Beginner
Posts: 29
Joined: Sun Nov 29, 2015 2:57 pm

Re: Autostart script

Postby afawaz » Thu Mar 24, 2016 9:32 pm

HarryPotter wrote:Dont know why it doesnt work for you. My mount script is doing its job on /usr/syno/etc/rc.d without any issues.


Are you running on DSM 6 ?
on my system (just updated to DSM 6) this directory has been removed after update !
User avatar
HarryPotter
Honorary Moderator
Honorary Moderator
Posts: 19251
Joined: Mon Oct 23, 2006 12:48 pm
Location: Switzerland

Re: Autostart script

Postby HarryPotter » Thu Mar 24, 2016 9:35 pm

Yes, the new directory is /usr/syno/etc.defaults/rc.sysv
*Please do not Private Message me for support questions; leave it on the forum so all members can learn. Thanks!*

DS718+ / DSM 6.2-23511 / ST4000VN000-2AH166 / SA400S37120G SSD cache /16 GB RAM
DS415+ / DSM 6.2-23511

LMS 7.9.1-166, 2 Squeezebox 3 + Boom

APC Smart UPS SUA750i
Rosen32
Student
Student
Posts: 69
Joined: Thu Mar 10, 2016 8:10 pm

Re: Autostart script

Postby Rosen32 » Sat May 21, 2016 4:38 pm

On the same subject – Autorun:

Does anyone knwo how or where to put commandline(s) to execute scripts in DS1515+ (DSM6) when inserting SD-card in reader (makes changes of UDEV-event "add"?

Check out this thread:
https://forum.synology.com/enu/viewtopi ... 47#p436047

best,
madivad
I'm New!
I'm New!
Posts: 5
Joined: Wed Jan 20, 2016 1:16 am

Re: Autostart script

Postby madivad » Fri Aug 04, 2017 2:38 am

HarryPotter wrote:Dont know why it doesnt work for you. My mount script is doing its job on /usr/syno/etc/rc.d without any issues.

Could you share your script for us?
User avatar
HarryPotter
Honorary Moderator
Honorary Moderator
Posts: 19251
Joined: Mon Oct 23, 2006 12:48 pm
Location: Switzerland

Re: Autostart script

Postby HarryPotter » Fri Aug 04, 2017 10:42 am

example:

on boot-up: mount --bind /volume1/@download /volume1/amule
on shutdown: umount /volume1/amule
*Please do not Private Message me for support questions; leave it on the forum so all members can learn. Thanks!*

DS718+ / DSM 6.2-23511 / ST4000VN000-2AH166 / SA400S37120G SSD cache /16 GB RAM
DS415+ / DSM 6.2-23511

LMS 7.9.1-166, 2 Squeezebox 3 + Boom

APC Smart UPS SUA750i
luckyearl
I'm New!
I'm New!
Posts: 1
Joined: Sun Sep 03, 2017 9:59 pm

Re: Autostart script

Postby luckyearl » Sun Sep 03, 2017 10:10 pm

Hi
Continuing on the same Autostart theme, the following script fails to start at boot
Works well when ssh with puttyy-> sudo -i to root & run

Script : S99mediamon.sh
Location : /usr/local/etc/rc.d/S99mediamon.sh
Permission: chmod 755
Owner: root

Please advise how I could fix it
Cheers
script

Code: Select all

#!/bin/sh
# /usr/syno/etc/rc.d/S99mediamon.sh

case "$1" in
  start|"")
    #start the monitoring daemon
    python3 /volume1/homes/admin/mediamon.py
    ;;
  restart|reload|force-reload)
    echo "Error: argument '$1' not supported" >&2
    exit 3
    ;;
  stop)
    kill `cat /var/run/mediamon.pid`
    ;;
  *)
    echo "Usage: S99mediamon.sh [start|stop]" >&2
    exit 3
    ;;
esac
User avatar
HarryPotter
Honorary Moderator
Honorary Moderator
Posts: 19251
Joined: Mon Oct 23, 2006 12:48 pm
Location: Switzerland

Re: Autostart script

Postby HarryPotter » Mon Sep 04, 2017 6:38 am

I dont know if start scripts in rc.d still work. It is much easier now through DSM - Ttask Scheduler - Create - Triggered task
*Please do not Private Message me for support questions; leave it on the forum so all members can learn. Thanks!*

DS718+ / DSM 6.2-23511 / ST4000VN000-2AH166 / SA400S37120G SSD cache /16 GB RAM
DS415+ / DSM 6.2-23511

LMS 7.9.1-166, 2 Squeezebox 3 + Boom

APC Smart UPS SUA750i
nixjps
Apprentice
Apprentice
Posts: 90
Joined: Fri Jun 09, 2017 1:39 pm

Re: Autostart script

Postby nixjps » Mon Sep 04, 2017 10:29 am

Hi,

I would be tempted to second HarryPotter recommendation.

As for your issue... I believe Latest DSM version still processes /usr/local/etc/rc.d/.
You wrote your script fails to start. Could you elaborate? Any error messages in /var/log/*?

At a first glance I wound think about two things.

You haven't explicitly set python3 path, so you assume shell will find it in your PATH environment variable. Are you sure you have python's path in it? Have you tried with absolute path.

Sudo -i runs with a shell connected to a terminal, rc.d/* scripts processed at boot up do not. May be your py script needs some additional work in such context (closing STDIN for instance).

Rgds,
DS916+ (8G) - DSM 6.1.3-15152u4 - ST8000VN0022-2EL112 x 3 - 1 SHR Disk Group - 2 volumes - Home Usage
DS216Play - DSM 6.1.3-15152u4 - ST4000DM000-1F2168 x 2 - Basic Disks - 2 Volumes - Off site backup of DS916+ and local browsing of Photos, Musics and Videos
DS916 and DS216Play MAN link (1Gb FFTH same ISP).
DS916 S2S -> DS216Play, HyperBackup of DS916 config & critical data to DS216Play. HyperBackup of DS216Play configuration and local data to DS916
tproko
Novice
Novice
Posts: 45
Joined: Sun Jun 11, 2017 8:58 am

Re: Autostart script

Postby tproko » Mon Sep 04, 2017 11:42 am

Hey, I had my mount script in /usr/local/etc/rc.d/S99mount.sh with the standard start/stop cases for such scripts (start mount, stop umount).
Worked with DSM 6.x

Another possibility is to use the taskmanger vis DSM/Settings. There you can place scripts for start/stop and insert the script code as well. More syno dependant, but you can skip ssh.

Return to “General Mods”

Who is online

Users browsing this forum: No registered users and 3 guests