Skip to content

Personal instructions

negan07 edited this page Apr 1, 2021 · 11 revisions

Services

Running a router service (firewall, wan, wlan, schedule ...) through rc cmd the router is able to execute commands or scripts before and after the service itself: this allows a deeper integration with original firmware purposes, like service pre-configurations, service inhibitions or post-modifications on running services.

service can be one of these common: wan (connection), wlan (wifi), firewall (ruleset), schedule (cronjob events) but also the others can be treated.

PRE service scripts

Located in: /etc/init.d/rc.pre

Stored in: /usr/etc/init.d/rc.pre

To add a command, edit with the internal editor vi the related pre script:

vi /etc/init.d/rc.pre/<service>_pre

Press i then make additions before exit 0 then save it pressing < ESC > then :wq (press: :q! to exit without saving) .

Restart the service itself with:

rc <service> restart

Store modifications permanently with:

cp -f /etc/init.d/rc.pre/<service>_pre /usr/etc/init.d/rc.pre/

Example:

Add some command before wifi restart event:

vi /etc/init.d/rc.post/wlan_pre

Press i then make additions before exit 0 then save it pressing < ESC > then :wq (press: :q! to exit without saving) .

Restart service with:

rc wlan restart

Store modifications permanently with:

cp -f /etc/init.d/rc.pre/wlan_pre /usr/etc/init.d/rc.pre/

POST service scripts

Located in: /etc/init.d/rc.post

Stored in: /usr/etc/init.d/rc.post

To add a command, edit with the internal editor vi the related post script:

vi /etc/init.d/rc.post/<service>_post

Press i then make additions before exit 0 then save it pressing < ESC > then :wq (press: :q! to exit without saving) .

Restart service with:

rc <service> restart

Store modifications permanently with:

cp -f /etc/init.d/rc.post/<service>_post /usr/etc/init.d/rc.post/

Personal Post wifi commands

To add a post wifi command, type:

anc nvram add anc_wlan_opt "<postcmdtorun>"

To remove a previously inserted rule type:

anc nvram del anc_wlan_opt "<postcmdtorun>"

Empty command list typing:

anc nvram unset anc_wlan_opt

Store modificated settings typing:

nvram commit

Restart service with:

rc wlan restart

Runlevel scripts

Similar to classic Debian machines boot startup sequence, after running /usr/etc/rcS init script, the router executes /etc/init.d/rcS/K[0-9][0-9]* then /etc/init.d/rcS/S[0-9][0-9]* scripts present as symlinks in alphabetical order.

Commands are numbered from [K/S]00 to [K/S]99 .

While classic Debian has many runlevel typically named rc.[0-6] ... in this router there is only one common runlevel named S .

Runlevel boot can be disabled at all typing: nvram set anc_boot_disable=1

Runlevel boot can be enabled at all typing: nvram unset anc_boot_disable

K runlevel

/etc/init.d/rcS.d/K* commands are run with stop parameter and they are historically used to stop previous runlevel services: in this tiny stage, there is only one runlevel so it is generally used to kill unwanted or useless processes run at boot by the router itself.

Runlevel K stage boot can be disabled typing: nvram set anc_kscripts_disable=1

Runlevel K stage boot can be enabled typing: nvram set anc_kscripts_disable=0

Add a kill command typing:

anc nvram add anc_kill_opt <cmd>

Remove a kill command typing:

anc nvram del anc_kill_opt <cmd>

Empty kill command list typing:

anc nvram unset anc_kill_opt

Store modificated settings typing:

nvram commit

Settings will be applied at next reboot.

S runlevel

/etc/init.d/rcS.d/S* commands are run with 'start' parameter and they are historically used to run services at the current runlevel.

A common example of S runlevel usage is openssh sshd daemon startup at boot.

Runlevel S stage boot can be disabled typing: nvram set anc_sscripts_disable=1

Runlevel S stage boot can be enabled typing: nvram set anc_sscripts_disable=0

Add a kill command typing:

anc nvram add anc_startup_opt <cmd>

Remove a kill command typing:

anc nvram del anc_startup_opt <cmd>

Empty kill command list typing:

anc nvram unset anc_startup_opt

Store modificated settings typing:

nvram commit

Settings will be applied at next reboot.