From 64089ae6bb7ec7f7cfd060aa82a13e0d4d81833f Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 13 Nov 2015 17:35:26 +0200 Subject: [PATCH] init script refactoring --- board/bananapi/overlay/etc/init.d/S00hostname | 44 --------- board/bananapi/overlay/etc/init.d/boardsn | 5 + board/common/overlay/etc/fstab | 4 +- board/common/overlay/etc/init.d/S00hostname | 43 --------- board/common/overlay/etc/init.d/S00osinit | 94 +++++++++++++++++++ .../overlay/etc/init.d/{S60date => S50date} | 0 .../overlay/etc/init.d/{S80crond => S51crond} | 0 .../overlay/etc/init.d/{S50sshd => S60sshd} | 0 .../etc/init.d/{S70proftpd => S61proftpd} | 0 .../overlay/etc/init.d/{S91smb => S62smb} | 0 .../etc/init.d/{S95motioneye => S85motioneye} | 0 board/common/overlay/etc/init.d/S99userinit | 22 +++++ board/common/overlay/etc/init.d/boardsn | 4 + board/common/overlay/etc/init.d/functions | 3 + board/common/overlay/etc/init.d/rcK | 32 +++---- board/common/overlay/etc/init.d/rcS | 43 ++++----- board/common/overlay/etc/init.d/vars | 6 ++ board/common/overlay/etc/inittab | 11 --- board/common/overlay/etc/os.conf | 2 + board/common/overlay/etc/version | 5 + board/common/overlay/sbin/loadmodules | 12 --- board/common/overlay/sbin/remountrw | 19 ---- board/common/overlay/sbin/userinit | 8 -- .../cubietruck/overlay/etc/init.d/S00hostname | 43 --------- board/cubietruck/overlay/etc/init.d/boardsn | 5 + board/odroidc1/overlay/etc/init.d/S00hostname | 44 --------- board/odroidc1/overlay/etc/init.d/boardsn | 5 + .../etc/init.d/{S03brownout => S05brownout} | 0 .../etc/init.d/{S94streameye => S84streameye} | 0 board/raspberrypi/overlay/etc/init.d/boardsn | 5 + .../etc/init.d/{S03brownout => S05brownout} | 0 .../etc/init.d/{S94streameye => S84streameye} | 0 board/raspberrypi2/overlay/etc/init.d/boardsn | 5 + 33 files changed, 197 insertions(+), 267 deletions(-) delete mode 100755 board/bananapi/overlay/etc/init.d/S00hostname create mode 100755 board/bananapi/overlay/etc/init.d/boardsn delete mode 100755 board/common/overlay/etc/init.d/S00hostname create mode 100755 board/common/overlay/etc/init.d/S00osinit rename board/common/overlay/etc/init.d/{S60date => S50date} (100%) rename board/common/overlay/etc/init.d/{S80crond => S51crond} (100%) rename board/common/overlay/etc/init.d/{S50sshd => S60sshd} (100%) rename board/common/overlay/etc/init.d/{S70proftpd => S61proftpd} (100%) rename board/common/overlay/etc/init.d/{S91smb => S62smb} (100%) rename board/common/overlay/etc/init.d/{S95motioneye => S85motioneye} (100%) create mode 100755 board/common/overlay/etc/init.d/S99userinit create mode 100755 board/common/overlay/etc/init.d/boardsn create mode 100755 board/common/overlay/etc/init.d/functions create mode 100755 board/common/overlay/etc/init.d/vars create mode 100644 board/common/overlay/etc/os.conf create mode 100644 board/common/overlay/etc/version delete mode 100755 board/common/overlay/sbin/loadmodules delete mode 100755 board/common/overlay/sbin/remountrw delete mode 100755 board/common/overlay/sbin/userinit delete mode 100755 board/cubietruck/overlay/etc/init.d/S00hostname create mode 100755 board/cubietruck/overlay/etc/init.d/boardsn delete mode 100755 board/odroidc1/overlay/etc/init.d/S00hostname create mode 100755 board/odroidc1/overlay/etc/init.d/boardsn rename board/raspberrypi/overlay/etc/init.d/{S03brownout => S05brownout} (100%) rename board/raspberrypi/overlay/etc/init.d/{S94streameye => S84streameye} (100%) create mode 100755 board/raspberrypi/overlay/etc/init.d/boardsn rename board/raspberrypi2/overlay/etc/init.d/{S03brownout => S05brownout} (100%) rename board/raspberrypi2/overlay/etc/init.d/{S94streameye => S84streameye} (100%) create mode 100755 board/raspberrypi2/overlay/etc/init.d/boardsn diff --git a/board/bananapi/overlay/etc/init.d/S00hostname b/board/bananapi/overlay/etc/init.d/S00hostname deleted file mode 100755 index ed7d811214..0000000000 --- a/board/bananapi/overlay/etc/init.d/S00hostname +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -start() { - echo -n "Setting hostname: " - - sn=$(cat /sys/class/net/eth0/address | tr -d ':') - sn=${sn: -8} - echo $sn > /var/cache/serial_number - hostname="meye-$sn" - /bin/hostname $hostname - echo "127.0.0.1 localhost $hostname" > /etc/hosts - - echo "done" -} - -stop() { - echo -n -} - -restart() { - stop - start -} - -case "$1" in - start) - start - ;; - - stop) - stop - ;; - - restart|reload) - restart - ;; - - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 -esac - -exit $? - diff --git a/board/bananapi/overlay/etc/init.d/boardsn b/board/bananapi/overlay/etc/init.d/boardsn new file mode 100755 index 0000000000..94a7db385d --- /dev/null +++ b/board/bananapi/overlay/etc/init.d/boardsn @@ -0,0 +1,5 @@ +#!/bin/bash + +sn=$(cat /sys/class/net/eth0/address | tr -d ':') +echo ${sn: -8} + diff --git a/board/common/overlay/etc/fstab b/board/common/overlay/etc/fstab index 5da62f5656..a138aac079 100644 --- a/board/common/overlay/etc/fstab +++ b/board/common/overlay/etc/fstab @@ -1,11 +1,11 @@ # -/dev/mmcblk0p1 /boot vfat ro,defaults 0 0 -/dev/mmcblk0p3 /data ext4 defaults,noatime 0 0 proc /proc proc defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 tmpfs /dev/shm tmpfs mode=0777 0 0 tmpfs /tmp tmpfs mode=1777 0 0 sysfs /sys sysfs defaults 0 0 +/dev/mmcblk0p1 /boot vfat ro,defaults 0 0 +/dev/mmcblk0p3 /data ext4 defaults,noatime 0 0 /data/output /home/ftp/sdcard rbind rbind 0 0 /data/media /home/ftp/storage rbind rbind 0 0 diff --git a/board/common/overlay/etc/init.d/S00hostname b/board/common/overlay/etc/init.d/S00hostname deleted file mode 100755 index 67e564aa1c..0000000000 --- a/board/common/overlay/etc/init.d/S00hostname +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -start() { - echo -n "Setting hostname: " - - sn=$(cat /proc/cpuinfo | grep Serial | tr -d ' ' | cut -d ':' -f 2) - sn=${sn: -8} - echo $sn > /var/cache/serial_number - hostname="meye-$sn" - /bin/hostname $hostname - echo "127.0.0.1 localhost $hostname" > /etc/hosts - - echo "done" -} - -stop() { - echo -n -} - -restart() { - stop - start -} - -case "$1" in - start) - start - ;; - - stop) - stop - ;; - - restart|reload) - restart - ;; - - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 -esac - -exit $? diff --git a/board/common/overlay/etc/init.d/S00osinit b/board/common/overlay/etc/init.d/S00osinit new file mode 100755 index 0000000000..58487cdcc6 --- /dev/null +++ b/board/common/overlay/etc/init.d/S00osinit @@ -0,0 +1,94 @@ +#!/bin/bash + +sys_conf="/etc/os.conf" +conf="/data/etc/os.conf" + +if [ -f $sys_conf ] && ! [ -f $conf ]; then + cp $sys_conf $conf +fi + +if [ -f $conf ]; then + source $conf +fi + +mount_all() { + echo -n "Mounting filesystems: " + + /bin/mkdir -p /dev/pts + /bin/mkdir -p /dev/shm + /bin/mount --make-shared / + /bin/mount -a + + echo "done" + + if [ "$os_debug" == "true" ]; then + echo -n "Remounting boot partition read-write: " + mount -o remount,rw /boot + [ $? == 0 ] && echo "done" || echo "failed" + + echo -n "Remounting root partition read-write: " + mount -o remount,rw / + [ $? == 0 ] && echo "done" || echo "failed" + fi +} + +unmount_all() { + /bin/umount -a -r + /sbin/swapoff -a +} + +set_hostname() { + echo -n "Setting hostname: " + + if [ -f /data/etc/hostname ]; then + hostname=$(cat /data/etc/hostname) + else + hostname="$os_prefix-$board_sn" + fi + + /bin/hostname $hostname + echo "127.0.0.1 localhost $hostname" > /etc/hosts + + echo "done" +} + +load_modules() { + echo -n "Loading kernel modules: " + + if [ -r /etc/modules ]; then + cat /etc/modules | while read line; do test -n "$line" && /sbin/modprobe $line; done + fi + + if [ -r /data/etc/modules ]; then + cat /data/etc/modules | while read line; do test -n "$line" && /sbin/modprobe $line; done + fi + + echo "done" +} + +start() { + mount_all + set_hostname + load_modules +} + +stop() { + unmount_all +} + +case "$1" in + start) + start + ;; + + stop) + stop + ;; + + *) + echo "Usage: $0 {start|stop}" + exit 1 +esac + +exit $? + diff --git a/board/common/overlay/etc/init.d/S60date b/board/common/overlay/etc/init.d/S50date similarity index 100% rename from board/common/overlay/etc/init.d/S60date rename to board/common/overlay/etc/init.d/S50date diff --git a/board/common/overlay/etc/init.d/S80crond b/board/common/overlay/etc/init.d/S51crond similarity index 100% rename from board/common/overlay/etc/init.d/S80crond rename to board/common/overlay/etc/init.d/S51crond diff --git a/board/common/overlay/etc/init.d/S50sshd b/board/common/overlay/etc/init.d/S60sshd similarity index 100% rename from board/common/overlay/etc/init.d/S50sshd rename to board/common/overlay/etc/init.d/S60sshd diff --git a/board/common/overlay/etc/init.d/S70proftpd b/board/common/overlay/etc/init.d/S61proftpd similarity index 100% rename from board/common/overlay/etc/init.d/S70proftpd rename to board/common/overlay/etc/init.d/S61proftpd diff --git a/board/common/overlay/etc/init.d/S91smb b/board/common/overlay/etc/init.d/S62smb similarity index 100% rename from board/common/overlay/etc/init.d/S91smb rename to board/common/overlay/etc/init.d/S62smb diff --git a/board/common/overlay/etc/init.d/S95motioneye b/board/common/overlay/etc/init.d/S85motioneye similarity index 100% rename from board/common/overlay/etc/init.d/S95motioneye rename to board/common/overlay/etc/init.d/S85motioneye diff --git a/board/common/overlay/etc/init.d/S99userinit b/board/common/overlay/etc/init.d/S99userinit new file mode 100755 index 0000000000..9ada77a624 --- /dev/null +++ b/board/common/overlay/etc/init.d/S99userinit @@ -0,0 +1,22 @@ +#!/bin/bash + +case "$1" in + start) + if [ -r /data/etc/userinit.sh ]; then + echo -n "Executing user init script: " + /bin/bash /data/etc/userinit.sh + echo "done" + fi + ;; + + stop) + true + ;; + + *) + echo "Usage: $0 {start|stop}" + exit 1 +esac + +exit $? + diff --git a/board/common/overlay/etc/init.d/boardsn b/board/common/overlay/etc/init.d/boardsn new file mode 100755 index 0000000000..2e82bbd253 --- /dev/null +++ b/board/common/overlay/etc/init.d/boardsn @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "00000000" + diff --git a/board/common/overlay/etc/init.d/functions b/board/common/overlay/etc/init.d/functions new file mode 100755 index 0000000000..7a693aac0b --- /dev/null +++ b/board/common/overlay/etc/init.d/functions @@ -0,0 +1,3 @@ +#!/bin/bash + + diff --git a/board/common/overlay/etc/init.d/rcK b/board/common/overlay/etc/init.d/rcK index 7cb7f67eb8..74fcda1b50 100755 --- a/board/common/overlay/etc/init.d/rcK +++ b/board/common/overlay/etc/init.d/rcK @@ -1,31 +1,27 @@ #!/bin/sh -BOOT_LOG=/var/log/boot.log -PID_FILE=/tmp/rc.pid +boot_log=/var/log/boot.log +pid_file=/tmp/rc.pid -echo "---- shutting down ----" >> $BOOT_LOG +source /etc/init.d/vars +source /etc/init.d/functions -# stop all init scripts in /etc/init.d +echo "---- shutting down $os_name $os_version ----" >> $boot_log + +# stop all init scripts in /etc/init.d, # executing them in numerical order. (for i in /etc/init.d/S??*; do [ ! -f "$i" ] && continue [ -f /data/etc/no_$(basename $i) ] && continue - case "$i" in - *.sh) # Source shell script for speed. - ( - trap - INT QUIT TSTP - set stop - . $i - ) - ;; - *) # No sh extension, so fork subprocess. - $i stop - ;; - esac -done& echo $! > $PID_FILE) | tee -a $BOOT_LOG & + ( + trap - INT QUIT TSTP + set stop + . $i + ) +done& echo $! > $pid_file) | tee -a $boot_log & -pid=$(cat $PID_FILE) +pid=$(cat $pid_file) while kill -0 $pid 2>/dev/null; do sleep 1 done diff --git a/board/common/overlay/etc/init.d/rcS b/board/common/overlay/etc/init.d/rcS index f318f38110..925bca7861 100755 --- a/board/common/overlay/etc/init.d/rcS +++ b/board/common/overlay/etc/init.d/rcS @@ -1,43 +1,40 @@ #!/bin/sh -BOOT_LOG=/var/log/boot.log -PID_FILE=/tmp/rc.pid +boot_log=/var/log/boot.log +pid_file=/tmp/rc.pid if ! [ -d /var/log ]; then - # the very first boot won't have the /var/log directory - BOOT_LOG=/tmp/boot.log - TMP_LOG=yes + # at the very first boot, + # we won't have the /var/log directory + boot_log=/tmp/boot.log + tmp_log=yes fi -echo "---- booting ----" >> $BOOT_LOG +source /etc/init.d/vars +source /etc/init.d/functions -# start all init scripts in /etc/init.d +echo "---- booting $os_name $os_version----" >> $boot_log + +# start all init scripts in /etc/init.d, # executing them in numerical order. (for i in /etc/init.d/S??*; do [ ! -f "$i" ] && continue [ -f /data/etc/no_$(basename $i) ] && continue - case "$i" in - *.sh) # Source shell script for speed. - ( - trap - INT QUIT TSTP - set start - . $i - ) - ;; - *) # No sh extension, so fork subprocess. - $i start - ;; - esac -done& echo $! > $PID_FILE) | tee -a $BOOT_LOG & + ( + trap - INT QUIT TSTP + set start + . $i + ) +done& echo $! > $pid_file) | tee -a $boot_log & -pid=$(cat $PID_FILE) +pid=$(cat $pid_file) while kill -0 $pid 2>/dev/null; do sleep 1 done -if [ -n "$TMP_LOG" ]; then +if [ -n "$tmp_log" ]; then # persist the boot log at first boot - mv $BOOT_LOG /var/log + mv $boot_log /var/log fi diff --git a/board/common/overlay/etc/init.d/vars b/board/common/overlay/etc/init.d/vars new file mode 100755 index 0000000000..1b1fed0e91 --- /dev/null +++ b/board/common/overlay/etc/init.d/vars @@ -0,0 +1,6 @@ +#!/bin/bash + +source /etc/version +board=$(cat /etc/board) +board_sn=$(/etc/init.d/boardsn) + diff --git a/board/common/overlay/etc/inittab b/board/common/overlay/etc/inittab index b0cf55b234..08afd810c3 100644 --- a/board/common/overlay/etc/inittab +++ b/board/common/overlay/etc/inittab @@ -14,16 +14,7 @@ # process == program to run # Startup the system -null::sysinit:/bin/mount -t proc proc /proc -null::sysinit:/bin/mkdir -p /dev/pts -null::sysinit:/bin/mkdir -p /dev/shm -null::sysinit:/bin/mount --make-shared / -null::sysinit:/bin/mount -a -null::sysinit:/sbin/remountrw -null::sysinit:/sbin/loadmodules -# now run any rc scripts ::sysinit:/etc/init.d/rcS -::sysinit:/sbin/userinit # Put a getty on the serial port tty1::respawn:/sbin/getty -L tty1 115200 vt100 @@ -34,6 +25,4 @@ tty1::respawn:/sbin/getty -L tty1 115200 vt100 # Stuff to do before rebooting null::shutdown:/etc/init.d/rcK -null::shutdown:/bin/umount -a -r -null::shutdown:/sbin/swapoff -a diff --git a/board/common/overlay/etc/os.conf b/board/common/overlay/etc/os.conf new file mode 100644 index 0000000000..1a62fb3894 --- /dev/null +++ b/board/common/overlay/etc/os.conf @@ -0,0 +1,2 @@ +os_debug="false" + diff --git a/board/common/overlay/etc/version b/board/common/overlay/etc/version new file mode 100644 index 0000000000..df06b7ebda --- /dev/null +++ b/board/common/overlay/etc/version @@ -0,0 +1,5 @@ +os_name="motionEyeOS" +os_short_name="motioneyeos" +os_prefix="meye" +os_version="20151103" + diff --git a/board/common/overlay/sbin/loadmodules b/board/common/overlay/sbin/loadmodules deleted file mode 100755 index 42e25ea961..0000000000 --- a/board/common/overlay/sbin/loadmodules +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -if [ -r /etc/modules ]; then - cat /etc/modules | while read line; do test -n "$line" && /sbin/modprobe $line; done -fi - -if [ -r /data/etc/modules ]; then - cat /data/etc/modules | while read line; do test -n "$line" && /sbin/modprobe $line; done -fi - -exit 0 - diff --git a/board/common/overlay/sbin/remountrw b/board/common/overlay/sbin/remountrw deleted file mode 100755 index ce2d176a9b..0000000000 --- a/board/common/overlay/sbin/remountrw +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -PATH=/bin:/usr/bin:/sbin:/usr/sbin -motioneye_conf=/data/etc/motioneye.conf - -test -f $motioneye_conf || exit 0 - -if grep 'log-level debug' $motioneye_conf >/dev/null; then - echo -n "Remounting boot partition read-write: " - mount -o remount,rw /boot - [ $? == 0 ] && echo "done" || echo "failed" - - echo -n "Remounting root partition read-write: " - mount -o remount,rw / - [ $? == 0 ] && echo "done" || echo "failed" -fi - -exit 0 - diff --git a/board/common/overlay/sbin/userinit b/board/common/overlay/sbin/userinit deleted file mode 100755 index e79c4e64cb..0000000000 --- a/board/common/overlay/sbin/userinit +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -if [ -r /data/etc/userinit.sh ]; then - /bin/bash /data/etc/userinit.sh -fi - -exit 0 - diff --git a/board/cubietruck/overlay/etc/init.d/S00hostname b/board/cubietruck/overlay/etc/init.d/S00hostname deleted file mode 100755 index 938cbbef3b..0000000000 --- a/board/cubietruck/overlay/etc/init.d/S00hostname +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -start() { - echo -n "Setting hostname: " - - sn=$(cat /sys/class/net/eth0/address | tr -d ':') - sn=${sn: -8} - echo $sn > /var/cache/serial_number - hostname="meye-$sn" - /bin/hostname $hostname - echo "127.0.0.1 localhost $hostname" > /etc/hosts - - echo "done" -} - -stop() { - echo -n -} - -restart() { - stop - start -} - -case "$1" in - start) - start - ;; - - stop) - stop - ;; - - restart|reload) - restart - ;; - - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 -esac - -exit $? diff --git a/board/cubietruck/overlay/etc/init.d/boardsn b/board/cubietruck/overlay/etc/init.d/boardsn new file mode 100755 index 0000000000..94a7db385d --- /dev/null +++ b/board/cubietruck/overlay/etc/init.d/boardsn @@ -0,0 +1,5 @@ +#!/bin/bash + +sn=$(cat /sys/class/net/eth0/address | tr -d ':') +echo ${sn: -8} + diff --git a/board/odroidc1/overlay/etc/init.d/S00hostname b/board/odroidc1/overlay/etc/init.d/S00hostname deleted file mode 100755 index ed7d811214..0000000000 --- a/board/odroidc1/overlay/etc/init.d/S00hostname +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -start() { - echo -n "Setting hostname: " - - sn=$(cat /sys/class/net/eth0/address | tr -d ':') - sn=${sn: -8} - echo $sn > /var/cache/serial_number - hostname="meye-$sn" - /bin/hostname $hostname - echo "127.0.0.1 localhost $hostname" > /etc/hosts - - echo "done" -} - -stop() { - echo -n -} - -restart() { - stop - start -} - -case "$1" in - start) - start - ;; - - stop) - stop - ;; - - restart|reload) - restart - ;; - - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 -esac - -exit $? - diff --git a/board/odroidc1/overlay/etc/init.d/boardsn b/board/odroidc1/overlay/etc/init.d/boardsn new file mode 100755 index 0000000000..94a7db385d --- /dev/null +++ b/board/odroidc1/overlay/etc/init.d/boardsn @@ -0,0 +1,5 @@ +#!/bin/bash + +sn=$(cat /sys/class/net/eth0/address | tr -d ':') +echo ${sn: -8} + diff --git a/board/raspberrypi/overlay/etc/init.d/S03brownout b/board/raspberrypi/overlay/etc/init.d/S05brownout similarity index 100% rename from board/raspberrypi/overlay/etc/init.d/S03brownout rename to board/raspberrypi/overlay/etc/init.d/S05brownout diff --git a/board/raspberrypi/overlay/etc/init.d/S94streameye b/board/raspberrypi/overlay/etc/init.d/S84streameye similarity index 100% rename from board/raspberrypi/overlay/etc/init.d/S94streameye rename to board/raspberrypi/overlay/etc/init.d/S84streameye diff --git a/board/raspberrypi/overlay/etc/init.d/boardsn b/board/raspberrypi/overlay/etc/init.d/boardsn new file mode 100755 index 0000000000..16881c26f7 --- /dev/null +++ b/board/raspberrypi/overlay/etc/init.d/boardsn @@ -0,0 +1,5 @@ +#!/bin/bash + +sn=$(cat /proc/cpuinfo | grep Serial | tr -d ' ' | cut -d ':' -f 2) +echo ${sn: -8} + diff --git a/board/raspberrypi2/overlay/etc/init.d/S03brownout b/board/raspberrypi2/overlay/etc/init.d/S05brownout similarity index 100% rename from board/raspberrypi2/overlay/etc/init.d/S03brownout rename to board/raspberrypi2/overlay/etc/init.d/S05brownout diff --git a/board/raspberrypi2/overlay/etc/init.d/S94streameye b/board/raspberrypi2/overlay/etc/init.d/S84streameye similarity index 100% rename from board/raspberrypi2/overlay/etc/init.d/S94streameye rename to board/raspberrypi2/overlay/etc/init.d/S84streameye diff --git a/board/raspberrypi2/overlay/etc/init.d/boardsn b/board/raspberrypi2/overlay/etc/init.d/boardsn new file mode 100755 index 0000000000..16881c26f7 --- /dev/null +++ b/board/raspberrypi2/overlay/etc/init.d/boardsn @@ -0,0 +1,5 @@ +#!/bin/bash + +sn=$(cat /proc/cpuinfo | grep Serial | tr -d ' ' | cut -d ':' -f 2) +echo ${sn: -8} +