Saving data via .rc_shutdown

Discussion in 'Tarifa Firmware' started by bhbattaglin, Feb 14, 2006.

  1. bhbattaglin

    bhbattaglin Network Guru Member

    I would like to save some data to an ftp server before the router reboots (and /tmp) is cleared.
    I have a script file in /tmp which should create a tar file and then use ftpput to upload the file:
    /bin/tar -cvf data.tar /tmp/data
    /usr/bin/ftpput ....

    the script works correctly when invoked in telenet.
    Are there tricks/restrictions on what can be done in .rc_shutdown?

  2. jchuit

    jchuit Network Guru Member

    To bhbattaglin

    There is only the limit of the size, the Tarifa firmware above version b009 has a increased limit of 8192 bytes for the startup or shutdown script. The free space is more then 10 kbyte in NVRAM, you can check the available NVRAM space with nvram show.

    A source for knowing more about scripts:

    About tricks: i don't have them, but I know there are a lot (google).

    Rc_startup is executed shortly after the start of the services, Rc_shutdown is shortly executed before the shutdown of the services.


    Edit: Maybe some timing problems, if rc_shutdown is still executing and the services are at almost the same stopped, copying to the network can give some problems.
  3. bhbattaglin

    bhbattaglin Network Guru Member

    .rc_shutdown not working

    Thanks for the link however, I understand how shell scripts are written. The problem is that I do not believe the .rc_shutdown script is executed at all or perhaps is immediately killed by the shutdown process. Have you tested the .rc_shutdown script?
    Note that my script takes several seconds (5 or so) to execute). Does the reboot process wait for .rc_shutdown to complete before killing all processes?
  4. jchuit

    jchuit Network Guru Member

    Rc: the router control services.

    This morning I did a test: for this I made 2 scripts:

    One for Rc_startup:
    echo Rc start >> /tmp/status

    And one for Rc_shutdown:
    echo Rc stop >> /tmp/status

    I saved these two in NVRAM (Save settings buttton).

    OK, and here begins the story:
    Some of the temp. (/tmp/...) files are only writen one's at boot, this is also the case for the /tmp/.rc_startup and /tmp/.rc_shutdown file.
    This means first a reboot is needed, the rc_**** are then written.

    Some services are handeld by the RC process, these services are telnet, dhcp, firewall etc..... to stop these Router Control services type in telnet: rc stop, the services will stop. and rc start to start again. At the start of these services rc_startup is executed and at the stop rc_shutdown.

    You will see that the content of /tmp/status will have the correct status, and this means rc_shutdown works.

    Linux executes multiple processes at the same time, this is also the case with rc_shutdown, this means that while the rc_shutdown executes the router will continue processing the other commands.

  5. bhbattaglin

    bhbattaglin Network Guru Member

    rc restart OK but Reboot not OK

    The .rc_shutdown script does indeed work if an rc stop or rc restart is executed from telnet. The problem is with the reboot command, either from the Management.asp screen, or from the telnet command.
    With a reboot command or pressing reboot on the form, all processes are killed almost immediately (check how fast the telnet connection is broken compared with rc stop/restart). The .rc_shutdown script is NOT allowed to run to completion. It would be good if at least your "soft" reboot button, first allowed .rc_shutdown to complete before doing a "hard" reboot.
  6. jchuit

    jchuit Network Guru Member

    The rc_shutdown and rc_startup are made for the Router Control program.

    What you like is a change in the reboot command to wait with SIGTERM (to all processes) and first do a RC STOP.

    Soft Reboot is a reboot by the software (the wireless and wired controller are not effected).
    A hard reboot is a reset from the hardware, a timer resets the processor(s), this will happen after powering up.

  7. bhbattaglin

    bhbattaglin Network Guru Member

    I am not sure about the implementation details. I just think it would be nice if the reboot button on your web interface waited for the .rc_shutdown (or some other script ie. /tmp/.reboot) to complete before killing all processes and eventually clearing /tmp. Clearly if rebooting from LINUX (ie via telnet, cron, scripts with sleep, etc.) it is possible to save any data as desired before doing the reboot.
  8. jchuit

    jchuit Network Guru Member

    Maybe that's a good idea, for a future release, a reboot script in /temp/.reboot.

    And a firewall script can also be helpfull, or a wait intruction after the rc_shutdown script.

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice