T2 SDE RC Script Writing Guide

T2 SDE linux uses a SysV-style init system with specific formatting conventions and manual symlink management.

Disclaimer: This guide is based on analyzing one T2 SDE system with an LLM. I couldn’t find official documentation for T2 SDE init scripts, so this represents observations from that specific installation. Check existing scripts like /etc/init.d/sshd on your system first to verify the patterns described here actually match your installation.

Script Structure

1. Header Format

#!/bin/sh
#
# Desc: Brief description of the service
# Runlevel: <priority> <runlevels>
#

Example:

#!/bin/sh
#
# Desc: SSH reverse tunnel daemon
# Runlevel: 30 rcX rc3 rc5
#

Note: The # Runlevel: comment is documentation only - T2 SDE does NOT auto-detect it. You must manually create symlinks.

T2 SDE provides standard functions for consistent output:

title() {
    local x w="$(stty size 2>/dev/null </dev/tty | cut -d" " -f2)"
    [ -z "$w" ] && w="$(stty size </dev/console | cut -d" " -f2)"
    printf "%0$((w/2-1))s" | sed "s/ /. /g"
    echo -e "\e[768G\e[4D vv \r\e[36m$* \e[0m"
    error=0
}

status() {
    if [ $error -eq 0 ]; then
        echo -e "\e[1A\e[768G\e[5D|\e[32m OK \e[0m|"
    else
        echo -e "\e[1A\e[768G\e[5D\a|\e[1;31mFAIL\e[0m|"
    fi
}

3. Case Statement Structure

case "$1" in
    start)
        title "Starting service name"
        start_function || error=$?
        status
        ;;
    stop)
        title "Stopping service name"
        stop_function || error=$?
        status
        ;;
    restart)
        title "Restarting service name"
        restart_function || error=$?
        status
        ;;
    status)
        status_function
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
        ;;
esac

exit 0

Installation and Registration

1. Place Script in init.d

# Copy script to init.d (which is actually /sbin/init.d/)
cp your-script /etc/init.d/your-service
chmod +x /etc/init.d/your-service

T2 SDE requires manual symlink creation in runlevel directories:

# For runlevel 3 (multi-user with networking)
ln -sf ../init.d/your-service /etc/rc.d/rc3.d/S30your-service  # Start
ln -sf ../init.d/your-service /etc/rc.d/rc3.d/K70your-service  # Kill

# For runlevel 5 (graphical/X11)
ln -sf ../init.d/your-service /etc/rc.d/rc5.d/S30your-service
ln -sf ../init.d/your-service /etc/rc.d/rc5.d/K70your-service

# For runlevel X (T2 custom runlevel)
ln -sf ../init.d/your-service /etc/rc.d/rcX.d/X30your-service

3. Naming Convention

Start scripts: S<priority><name>

Kill scripts: K<priority><name>

X runlevel: X<priority><name>

4. Priority Guidelines

Common priority numbers (lower = earlier):

Kill priorities are typically reversed: 100 - start_priority

How T2 SDE Runs Scripts

From /etc/inittab:

l3:3:wait:/etc/rc.d/rc

The /etc/rc.d/rc script:

  1. Runs K* scripts from previous runlevel with stop argument
  2. Runs S* scripts from current runlevel with start argument
  3. Scripts are executed in numeric order
  4. Logs to /var/log/init.msg

Common Runlevels

Debugging

Check what scripts run at boot:

ls -la /etc/rc.d/rc3.d/

View boot log:

cat /var/log/init.msg | grep your-service

Test script manually:

/etc/rc.d/rc3.d/S30your-service start
/etc/init.d/your-service status

Check current runlevel:

runlevel
# Output: N 3 (previous=N, current=3)

Complete Example

See the ssh-tunnel script for a complete working example with:

Key Differences from Other Init Systems

  1. No automatic detection - Must manually create symlinks
  2. No update-rc.d or chkconfig - Manual symlink management only
  3. Symlinks in /etc/rc.d/rcX.d/ - Not /etc/rcX.d/
  4. Init scripts in /sbin/init.d/ - Accessed via /etc/init.d/ symlink
  5. Uses title() and status() - For consistent formatted output
  6. Logs to /var/log/init.msg - Via btee utility

Removal

To disable a service:

# Remove symlinks
rm /etc/rc.d/rc3.d/*your-service
rm /etc/rc.d/rc5.d/*your-service
rm /etc/rc.d/rcX.d/*your-service

# Optionally remove script
rm /etc/init.d/your-service