├── etc ├── sv │ ├── getty-ttyS0 │ │ └── run │ └── ssh │ │ ├── log │ │ └── run │ │ └── run ├── runit │ ├── 1 │ ├── 2 │ ├── 3 │ └── ctrlaltdel └── fstab └── README.rst /etc/sv/getty-ttyS0/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec utmpset -w ttyS0 3 | -------------------------------------------------------------------------------- /etc/sv/ssh/log/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | LOG=/var/log/ssh 5 | 6 | if [ ! -d "$LOG" ] ; then 7 | mkdir -p -m 0750 "$LOG" 8 | chown -R log:adm "$LOG" 9 | fi 10 | 11 | exec /usr/bin/chpst -u log:adm /usr/bin/drlog -t "$LOG" 12 | -------------------------------------------------------------------------------- /etc/runit/ctrlaltdel: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PATH=/sbin:/bin:/usr/sbin:/usr/bin 4 | MSG="System is going down in 14 seconds..." 5 | 6 | #echo 'disabled.' ; exit 7 | touch /etc/runit/stopit 8 | chmod 0100 /etc/runit/stopit && \ 9 | echo "$MSG" | wall 10 | exec sleep 14 11 | -------------------------------------------------------------------------------- /etc/runit/3: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | exec 2>&1 3 | 4 | PATH=/sbin:/bin:/usr/sbin:/usr/bin 5 | 6 | echo 'Waiting for services to stop...' 7 | sv -w196 force-stop /etc/service/* 8 | sv exit /etc/service/* 9 | 10 | echo 'Saving date/time...' 11 | date -u '+%m%d%H%M%Y.%S' > /var/lastdatetime 12 | 13 | -------------------------------------------------------------------------------- /etc/sv/ssh/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec 2>&1 3 | 4 | if [ -r /run/early-sshd.pid ] && ! [ "$RUN_EARLY" ] ; then 5 | kill "`cat /run/early-sshd.pid`" 6 | rm -f /run/early-sshd.pid 7 | sleep 1 8 | fi 9 | 10 | # sshd wants to be started with absolute pathname 11 | SSHD=$(which sshd) || sv down $(pwd) 12 | 13 | PRIVSEP_DIR=/var/run/sshd 14 | mkdir -p "$PRIVSEP_DIR" 15 | 16 | exec "$SSHD" -D -e 17 | 18 | # memory limits set by chpst are inherited to subprocesses, 19 | # disabled by default 20 | #exec chpst -m8000000 "$SSHD" -D -e 21 | -------------------------------------------------------------------------------- /etc/runit/2: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin 4 | 5 | #runsvchdir default >/dev/null 6 | 7 | set -x 8 | exec env - PATH=$PATH \ 9 | runsvdir -P /etc/service 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................' 10 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ============================= 2 | GuruPlug runit init scripts 3 | ============================= 4 | 5 | Works with 6 | ========== 7 | 8 | - Debian Wheezy. 9 | - GuruPlug with a miniSD card. If yours does not have a card plugged, you 10 | may need to edit the ``etc/runit/1`` and ``etc/fstab`` files. 11 | 12 | Gets you 13 | ======== 14 | 15 | - Blazing fast boot times (under 10 seconds). 16 | - Daemon supervision (using ``runit``). 17 | - Early SSH and serial line, for debugging boot issues. 18 | 19 | 20 | Needed tools / packages 21 | ======================= 22 | 23 | - dmon 24 | - runit 25 | - openssh-server 26 | - util-linux 27 | - bridge-utils 28 | - dhclient 29 | - ntpdate 30 | 31 | 32 | Instructions 33 | ============ 34 | 35 | .. todo:: Write instructions down. 36 | -------------------------------------------------------------------------------- /etc/fstab: -------------------------------------------------------------------------------- 1 | # 2 | # dev mountpoint fstype fsflags dump pass 3 | # 4 | tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0 5 | tmpfs /run tmpfs rw,nosuid 0 0 6 | devpts /dev/pts devpts rw,noexec,nosuid,gid=5,mode=620 0 0 7 | sysfs /sys sysfs rw,noexec,nosuid,nodev 0 0 8 | proc /proc proc rw,noexec,nosuid,nodev 0 0 9 | /dev/sdb /var/.sdhc ext4 rw,noatime,relatime 0 0 10 | 11 | # 12 | # Bind-mounts, very useful to remap things from the miniSD 13 | # 14 | /var/.sdhc/tmp /tmp none bind 0 0 15 | /var/.sdhc/tmp /var/tmp none bind 0 0 16 | /var/.sdhc/home /home none bind 0 0 17 | /var/.sdhc/var-www /var/www none bind 0 0 18 | /var/.sdhc/var-cache-apt /var/cache/apt none bind 0 0 19 | 20 | # 21 | # Swap files 22 | # 23 | /var/.sdhc/swap0 swap swap sw 0 0 24 | 25 | -------------------------------------------------------------------------------- /etc/runit/1: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # system one time tasks 3 | 4 | PATH=/sbin:/bin:/usr/sbin:/usr/bin 5 | 6 | # First of all, try to restore date/time: This sets a reasonable 7 | # initial time before the rest of services kick in by using the 8 | # last shutdown time. Some devices do not have a RTC and time 9 | # would be reset to some random value. It is better to have a 10 | # well-known value (even if old) than an older one. 11 | # 12 | if [ -r /var/lastdatetime ] ; then 13 | echo 'Restoring last-known date/time... ' 14 | T="`head -1 /var/lastdatetime`" 15 | T="`date -u "$T" 2> /dev/null`" 16 | if [ $? = 0 ] ; then 17 | echo " date/time: $T" 18 | else 19 | echo " failed restoring date/time" 20 | fi 21 | T='' 22 | fi 23 | 24 | # We *need* those. Note: Assumes entries present in /etc/fstab 25 | mount /proc 26 | mount /sys 27 | mount /run 28 | mkdir --mode=755 /run/lock /run/udev /run/network \ 29 | /run/resolvconf /run/resolvconf/interface 30 | 31 | # Make sure that the root filesystem is read-write 32 | mount -o rw,remount / 33 | 34 | # Reuse the udev initscript for now. This is ugly, but handles mounting the 35 | # tmpfs on /dev and some other crap. After udev is started, we can mount 36 | # /dev/pts and /dev/shm safely, so make sure that the directories are 37 | # present and try to mount everything in a single row. 38 | /etc/init.d/udev start 39 | udevadm settle 40 | echo "Waiting for /dev/sdb ..." 41 | while [ ! -r /dev/sdb ] ; do 42 | sleep 1 43 | done 44 | mount /var/.sdhc 45 | mkdir -p /dev/pts /dev/shm 46 | mount -a -t nonfs,nfs4,smbfs,cifs,ncp,ncpfs,coda,ocfs2,gfs,gfs2,ceph -O no_netdev 47 | swapon -a 48 | 49 | # Set the host name from /etc/hostname and sysctl options 50 | [ -r /etc/hostname ] && hostname "`head -1 /etc/hostname`" 51 | sysctl -p 52 | 53 | # Bring up network in a really shitty (but working) way. 54 | ifconfig lo 127.0.0.1 netmask 255.0.0.0 up 55 | dhclient -v -4 eth0 56 | 57 | # This sets the initial after booting time from hora.roa.es (stratum 1) 58 | # The IP address is used to avoid relying on DNS being available. 59 | ntpdate -b 150.214.94.5 60 | 61 | # Bring up interfaces for the wifi-wired bridge. All interfaces 62 | # MUST be configured before adding them to the bridge. 63 | ifconfig eth1 up 64 | ifconfig uap0 up 65 | /etc/network/uap start 66 | brctl addbr br0 67 | brctl stp br0 off 68 | brctl addif br0 eth1 69 | brctl addif br0 uap0 70 | ifconfig br0 172.16.0.1/12 up 71 | /etc/network/firewall 72 | 73 | # Ouch, this hurts 74 | rm -f /etc/resolv.conf 75 | echo 'nameserver 127.0.0.1' > /etc/resolv.conf 76 | 77 | # And now create [uw]tmp, otherwise logins will behave badly 78 | touch /run/utmp 79 | if grep -q ^utmp: /etc/group 80 | then 81 | chmod 664 /run/utmp 82 | chgrp utmp /run/utmp 83 | fi 84 | 85 | dmon -E RUN_EARLY=1 -S -s -p /run/early-sshd.pid -e /etc/sv/ssh/run 86 | dmon -E RUN_EARLY=1 -S -s -p /run/early-getty.pid -e /etc/sv/getty-ttyS0/run 87 | 88 | rm -f /sbin/runit.old 89 | touch /etc/runit/stopit 90 | chmod 0 /etc/runit/stopit 91 | 92 | --------------------------------------------------------------------------------