diff options
| author | Klaatu <[email protected]> | 2015-05-17 15:33:21 +1200 |
|---|---|---|
| committer | Klaatu <[email protected]> | 2015-05-17 15:33:21 +1200 |
| commit | b0de699679e8f1e39af847ed172d1ba605b4370c (patch) | |
| tree | 01dac00471d61f727394e508c613b29cff0ceae5 /scripts | |
bulk upload of source
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/conf | 18 | ||||
| -rwxr-xr-x | scripts/scan | 34 | ||||
| -rwxr-xr-x | scripts/service | 104 | ||||
| -rwxr-xr-x | scripts/tests.sh | 126 | ||||
| -rwxr-xr-x | scripts/update.sh | 27 |
5 files changed, 309 insertions, 0 deletions
diff --git a/scripts/conf b/scripts/conf new file mode 100755 index 0000000..b443af9 --- /dev/null +++ b/scripts/conf @@ -0,0 +1,18 @@ +#!/bin/sh + +if test "$1" = "" ; then + echo usage: $0 /dir/name + exit 100 +fi + +mkdir -m 755 $1 || exit 1 +cd $1 || exit 2 + +mkfifo -m 600 in || exit 3 +mkfifo -m 600 out || exit 4 + +ln -s /etc/ninit/sys sys || exit 5 +ln -s /etc/ninit/.sync .sync || exit 6 +ln -s /etc/ninit/.nsvc_help .nsvc_help || exit 7 + +ls -laF . diff --git a/scripts/scan b/scripts/scan new file mode 100755 index 0000000..aef0bab --- /dev/null +++ b/scripts/scan @@ -0,0 +1,34 @@ +#!/bin/sh +## *setup: $1=service S2=ninit_home $3=ninit_sys $4=pid +## end: $1=service S2=ninit_home $3=ninit_sys + +op='' +case $1 in + -u) op=u; shift; break;; + -o) op=o; shift; break;; + -d) op=d; shift; break;; +esac + +if test $# -lt 2 ; then + echo 'usage: ninit-scan [ -[uod] ] service ninit_home' + exit 1 +fi + +cd $2 || exit 2 + +if test "$1" = "" ; then + prefix='' +else + cd $1 || exit 3 + prefix=$1/ +fi + +for d in * ; do + if test -d $d -a -k $d ; then + x=$op + if test "$x" = "" ; then + test -f $d/respawn && x=u || x=o + fi + /bin/nsvc -$x $prefix$d + fi +done diff --git a/scripts/service b/scripts/service new file mode 100755 index 0000000..0255308 --- /dev/null +++ b/scripts/service @@ -0,0 +1,104 @@ +#!/bin/sh + +if test -z "$1" ; then + printf "%s\n\n" ' +usage: ninit-service [-Options] service(s) +usage: ninit-service -E service file + +Options: + -A ascii output + -C show end of lines; for cat + -L long lines; for ls + -E edit file; default editor: /bin/vi; change it with: + echo /usr/bin/emacs -nw > /etc/ninit/.editor + -H/other/home default home: /etc/ninit + +example: ninit-service `find /etc/ninit/ -type d`' + exit 1 +fi + + lsopt= +catopt= + home="/etc/ninit" +editor="/bin/vi" +cstart="\033\133\061\073\063\065\155" + cend="\033\133\060\073\063\071\155" + + +while true ; do + case $1 in + -E) shift; + [ -f $home/.editor ] && editor=`head -1 $home/.editor` + [ -z "$editor" ] && editor='/bin/vi' + test $# -ge 2 && exec $editor $home/$1/$2 + continue;; + -C*) catopt=-E ; shift; continue;; + -L*) lsopt=-l; shift; continue;; + -H*) home=`echo $1 | sed -e 's/^..//'`; shift; continue;; + -A*) cstart=""; cend=""; shift; continue;; + *) break ;; + esac +done + +while true; do + +cd $home || exit 1 +[ -z "$1" ] && exit 0 + +if ! cd $1 2>/dev/null ; then + printf "\n\n*** WARNING ***\t$cstart%s$cend is not a service\n\n" $1 + shift + continue +fi + +printf "\n\tservice: $cstart%s$cend\n" $1 + +if [ -d log -a ! -p log/in ] ; then + printf "\n*** WARNING *** %s$cstart%s$cend %s\n" \ + "you have not a FIFO " "log/in" + printf "%s\n\011%s\n\011%s\n\n" "create it with:" \ + "cd $home/$1" "mkfifo -m 600 log/in && ln -s log/in out" +fi + +ls -F $lsopt +printf "\n" + +#### links +for f in in out log run end; do + [ -e $f ] && printf "%s:\t" $f && ls -F -l $f | sed -s 's/ */ /g' +done +### + +### options +for f in respawn pause pause-wait ; do + [ -f $f ] && printf "option:\t%s\n" $f +done + +### first word +for f in nice uid gid sleep maxwait sync alarm pidfile \ + sysvinit-timeout; do + if [ -f $f ] ; then + read ans < $f + printf "%s:\t%s\n" $f $ans + fi +done + +### text files: +for f in params environ softlimit wait cron depends; do + if [ -f $f ] ; then + printf "\n$cstart%s$cend: ==>\n" $f + cat $catopt $f + printf '<==\n' + fi +done + +### dirs: +for f in depends.dir; do + if [ -d $f ] ; then + printf "\n$cstart%s$cend:\n" $f + ls -la $f + fi +done + +shift +done diff --git a/scripts/tests.sh b/scripts/tests.sh new file mode 100755 index 0000000..f07d807 --- /dev/null +++ b/scripts/tests.sh @@ -0,0 +1,126 @@ +#!/bin/sh +export PATH=/bin:/usr/bin:/sbin + +if [ "$UID" = "0" ] ; then + echo '**** WARNING **** Do not start this script as ROOT !!!' + echo 'Please, interrupt me! Otherwise I continue in 30 sec.' + sleep 30 +fi + +h=`pwd` +home=$h/home +export TIMEFORMAT=' elapsed time: %R' +export NINIT_HOME=$home + +cstart='' ; cend='' ; bad='' +tty -s 2>/dev/null +if [ $? -eq 0 ] ; then + # 30=black 31=red 32=green 33=yellow 34=blue ... 37=white + # 40=black 41=red ... backgrownd color + cstart='[1;47m[1;30m' ; cend='[0;39m'; bad='[1;44m[1;31m' +fi + +echo ' starting server' $cstart$h/ninit -H$home$cend +echo ' wait for this test more than 25 seconds' +echo ' no PANIC! the test terminates in 92 sec always' +echo + +start_time=`date +%s` + +print_env () { + if [ -f /proc/$ninit_pid/environ ] ; then + echo + echo ' '$1 $cstart \ + `./sleeprun -a4 tr '\000' ' ' < /proc/$ninit_pid/environ` $cend + fi +} + +do_it () { + X=$1; shift + echo ' starting '$cstart$@$cend' #' $X + ./sleeprun -a20 $@ + ret=$? + if [ $ret -ne 0 ] ; then + echo $bad'***** WARNING *****'$cend + echo 'Exit status of' $cstart$@$cend is $ret + sleep 3 + fi + return $ret +} + +do_it '(install HOME)' ./install-bin home < misc/HOME || exit 1 +test -f home/env/run || gzip -dc home.tar.gz | do_it '(unpack home)' tar -xv + +args="./sleeprun -a90 ./env -i NINIT_TIME=empty $h/ninit -H$home" +echo ' starting' $cstart$args$cend +$args & +ninit_pid=$! +echo ' ninit PID='$cstart$ninit_pid$cend + +do_it '(waiting the ninit to start)' sleep 1 +do_it '(list)' ./nsvc -L +time do_it '(wait 4s env)' ./nsvc -W4 env +do_it '(once)' ./nsvc -o sleep +do_it '(set respawning mode)' ./nsvc -R sleep +do_it '(list)' ./nsvc -L + +sleep 1 +do_it '(diagnostic)' ./nsvc sleep ; echo +do_it '(list)' ./nsvc -L +do_it '(list pids)' ./nsvc -g sleep default +do_it '(history)' ./nsvc -H + +echo ; echo ' reloading ninit' + +after=after-reload +do_it '' ps uwwww -p $ninit_pid ; echo +do_it '' ln -sf ninit $after + +print_env 'old ninit environ:' + +current_time=`date +%s` +args="./reload -v -a 20 -eNINIT_TIME=$current_time -e Hello=world" +args="$args -eYou_are=$USER -u $h/$after -H$home" +echo ' starting' $cstart$args$cend +time ./sleeprun -a30 $args + +print_env 'new ninit environ:' + +do_it '(sleep 4+3 sec; stopping do_update mode)' sleep 4 +do_it '' ps uwwww -p $ninit_pid ; echo +do_it '' sleep 3 + +echo +time do_it 'sync mode (max 3 sec)' ./nsvc -o S +do_it '(list)' ./nsvc -L +all=`./nsvc -L` +do_it '(remove cron flags)' ./nsvc -K0 $all +do_it '(down all services)' ./nsvc -d $all + +time do_it '(wait 1s all to finish)' ./nsvc -W1 $all +do_it '(list)' ./nsvc -L +do_it '(memory usage)' ./nsvc -D +do_it '(depends)' ./nsvc -D default + +[ -f /proc/$ninit_pid/statm ] && \ + do_it '(ninit daemon)' cat /proc/$ninit_pid/statm +do_it '(kill ninit daemon)' kill $ninit_pid +wait + +end_time=`date +%s` +./sleeprun -a4 rm -f $after + +n=`expr $end_time - $start_time` ; echo +echo ' test continues:' $cstart$n sec$cend + +echo +echo $cstart' Creating services in ./etc/ninit - Demo '$cend +do_it '(clean old ./etc/)' rm -r -f ./etc +do_it '(install ./etc/ninit/)' ./install-bin . < misc/ETC +do_it '(converter)' ./inittab /etc/inittab etc/ninit services.sh > /dev/null +do_it '(making services - demo)' ./services.sh +# do_it '' ls -F ./etc/ninit + +echo +echo Look now at $cstart./services.sh$cend and $cstart./etc/ninit/$cend. +echo diff --git a/scripts/update.sh b/scripts/update.sh new file mode 100755 index 0000000..c2ca22d --- /dev/null +++ b/scripts/update.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# $1 = $(DESTDIR) + +D=$1 +[ "$D" = "/" ] && D= + +echo +echo I will try to overwrite $D/sbin/ninit +echo If PID 1 is $D/sbin/ninit I will get probably an error + +[ -w $D/sbin/ninit ] || chmod 755 $D/sbin/ninit 2>/dev/null +./install-bin $D/sbin 'c:::755:/:ninit::' && exit 0 + +echo I got an error. I suppose PID 1 is $D/sbin/ninit +echo +echo I will try to replace $D/sbin/ninit with `pwd`/ninit +echo Please wait at least 30 seconds + +./sleeprun -a10 $D/sbin/ninit-reload -d > ninit.data && \ + ./sleeprun -a5 $D/sbin/ninit-reload -f ninit.data -u `pwd`/ninit && \ + ./install-bin $D/sbin 'c:::755:/:ninit::' && \ + ./sleeprun -a8 $D/sbin/ninit-reload -u $D/sbin/ninit && \ + exit 0 + +echo 'All fails! I will try simply ./install-bin' + +./install-bin $D/sbin 'x:::755:/:ninit::' |
