Run a Script At Bootime

From OpenFSG

Jump to: navigation, search

It is often useful to have a script automatically run when the FSG is booting up. This explains how to do that in few simple steps.

Instructions

  1. If you haven't already done so enable SSH, login to SSH, and "su" to root. Beware, Logging in as root is risky
  2. Create your script anywhere you want by typing vi scriptpath where scriptpath is the location and name of the script. In this example we will place it in /etc/init.d and call it custom_startup so the command would be:
    vi /etc/init.d/custom_startup
  3. place any commands you want run at startup in this file. For example, to change the TCP conneciton timeout to 20 minutes, paste the following line in the file.
    echo 1200 > /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_timeout_established
  4. Then type the following command to create a symbolic link in the /etc/rc directory.
    ln -s /etc/init.d/custom_startup /etc/rc/S99Acustom_startup
  5. Then type this command to allow the script to be executed by root
    chown root /etc/rc/S99Acustom_startup
    chmod ugo+rx /etc/init.d/custom_startup
    chmod ugo+rx /etc/rc/S99Acustom_startup
  6. You are done. Either reboot, or type sh /etc/rc/S99Acustom_startup


Note: Each time the FSG boots, it runs each script in /etc/rc that starts with "S" in alphabetical order. The order can be kinda confusing; alphanumerics are sorted like this: Spaces, 0, 1, ..., 9, Capitalized Alphabet, lowercase alphabet. So in order to add something that gets run after the S99twonky, you would have to name it S* where * is something that comes after "9" i.e. SA* would work, or any letter for that matter.

Personal tools