READYNAS 6.x Start Your Own Service – May Void Warranty

The Views Expressed Below Do not in any way reflect Internal Doctorine or Official Statements of Netgear Inc. These are just my notes – Use at your own Risk.

Enabling SSH may void your warranty. So dont blame me.

What this does:
IF you need to start a program or script or a service on boot, like a script of some sort. This will be for you.

Whats new in Readynas 6:
Systemd is used instead of sysvinit, so instead of using the /etc/init.d directory for start scripts. you will use the systemd service files (Which point to the scripts you want to launch). Personally I think its much easier.

What about Readynas 4 and 5:
They used sysvinit, and scripts started from /etc/init.d, but there was a script there already that would scrape the /var/spool/frontview/boot folder for any script to boot upon boot. Here is a full article on that topic: http://ram.kossboss.com/netgear-readynas-4-x-5-x-start-service-may-void-warranty/
Again do that at your own risk (as it may void warranty and I wont be responsible for it)
SUMMARY
########

(STEP1)

Make a service file like this (only edit the Description and the ExecStart):

(STEP2)

Enable it like so (so it starts on boot) :

Disable it like so (so it wont start on boot):

 

(STEP3)
Make the script/program that ExecStart points at (make sure its executable by root)

 

(STEP4)
Reboot your system thru the GUI or thru the CLI to test your service file

or:

 

DETAILED VERSION
###################

Make a service file that looks like this:

(STEP1)
Make a service file in /lib/systemd/system

[Unit] Description, just tell systemd what the script/service does. (its like the title of the service, the name of the app etc, as you can see it can have spaces)

[Service] ExecStart, this points at the executable script that should be started

[Install] WantedBy, this tells systemd where to put the service (at what runlevel to launch it). We always put “multi-user.target” here (thats the equivalent of the default runlevel). Note without this to stop and start the service upon boot you would need to run ln -s commands.

Can make it with this copy pastable Here-Document (a here-document is a cat command in bash that makes a file using an EOF word like EOF that tells the cat command where the text output ends – and thus to save it to the file mentioned in standard out which in this case will be a file in /lib/systemd/system)

(STEP2)

Make the script/ensure the program that is started by ExecStart actually exists and has +x (Executable permissions for root)

Example contents:

 

(STEP3)
Tell the device to launch that file upon start up.

NOTE: upon boot systemd scrapes the /etc/systemd/system folder for service files (via the symlinks that are there) to see what services to start (And at what order). We just specified default order (so I assume our script starts towards the end of the systemd service launchings)

Enable the service (make it start on boot):

Disable the service (make it not start on boot):

NOTE: the above command shows you what ln -s or rm commands it ran to enable/disable the script from launching on boot – these are the same commands that you would need to put in

NOTE: “systemctl start <service>” and “systemctl stop <service>” can be programmed in using more complex service files. However our script just needs to start upon boot and thats it.

If you didnt have the [Install] Section (and only had the [Unit] and the [Service] section) then you can use these symlinks to start the service on boot (or to not start the service on boot)
To start service upon boot (just make a symlink that points /etc/systemd/system/multi-user.target.wants/custom1.service to the original /lib/systemd/system/custom1.service – notice the syntax “ln -s <original> <symlink folder or symlink new filename>” – we used symlink folder, so the new symlink will have the same name so the new symlink will be /etc/systemd/system/multi-user.target.wants/custom1.service):

or:

 

To not start service upon boot (just kill the service):

or:

 

NOTE: Back in sysvinit days we would tell a script to launch from the runlevel folder (/etc/rc#.d/ where # is the runlevel), the files there were symlinks to the starter/stopper/restart scripts that sat in init.d (the symlink would be prefixed with S for start or K for kill or stop – there was a switch case, an if type of statement, that looked for the start,stop,restart arguments).

IN READYNAS 4 and 5 (which used sysvinit): However you didnt have to mess with init.d scripts, as there was a folder that was looked into upon boot (any script there would launch upon boot). So in the READYNAS4(and Readynas 5) units an exectuable script in here /var/spool/frontview/boot/ would start upon boot up. For more info: http://ram.kossboss.com/netgear-readynas-4-x-5-x-start-service-may-void-warranty/ Again do that at your own risk (as it may void warranty and I wont be responsible for it)

How it looks like when your service is enabled (will launch on boot – it will say its loaded)

How it looks like when your service is disabled

NOTE: you can refer to your service as custom1 or custom1.service

(STEP4)
Reboot your system thru the GUI or thru the CLI to test your service file

or:

 

EASY SCRIPTS TO COPY PASTE TO MAKE A SERVICE FILE READY TO GO
##################################################

2 Different copy paste scripts that do the same thing (one with a here-doc way to make a service file – another with an echo way to make a service file)

Just edit the first 3 variables
SERVICENAME
SERVICEDESCRIPTION
SCRIPTLOCATION
And copy paste the following scripts to
1) make the service file
2) make the script, and make it executable
3) tell you how to enable and disable the service file

MAKE EVERYTHING WITH 1 STEP – USING HERE-DOCUMENT

 

MAKE EVERYTHING WITH 1 STEP – USING ECHO

 

Leave a Reply

Your email address will not be published. Required fields are marked *