live-sdk

simple distro kit (livecd edition)
git clone git://parazyd.org/live-sdk.git
Log | Files | Refs | Submodules | README | LICENSE

boot_beep (2853B)


      1 #!/bin/sh
      2 # ----------------------------------------------------------------------
      3 #
      4 # This file is part of microdevuan, a set of scripts to create minimal 
      5 # devuan live images
      6 # 
      7 # ----------------------------------------------------------------------
      8 #
      9 # This program is free software: you can redistribute it and/or modify
     10 # it under the terms of the GNU General Public License as published by
     11 # the Free Software Foundation, either version 3 of the License, or (at
     12 # your option) any later version.
     13 # 
     14 # This program is distributed in the hope that it will be useful, but
     15 # WITHOUT ANY WARRANTY; without even the implied warranty of
     16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     17 # General Public License for more details.
     18 # 
     19 # You should have received a copy of the GNU General Public License
     20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     21 #
     22 # ----------------------------------------------------------------------
     23 #
     24 # (c) KatolaZ <katolaz@freaknet.org> (2016)
     25 #
     26 # ----------------------------------------------------------------------
     27 
     28 ### BEGIN INIT INFO
     29 # Provides:          boot_beep
     30 # Required-Start:    mountall
     31 # Required-Stop:     
     32 # Default-Start:     S
     33 # Default-Stop:      
     34 # Short-Description: Boot Beep Daemon
     35 ### END INIT INFO
     36 
     37 
     38 . /etc/default/boot_beep
     39 
     40 rm_hanging_instances(){
     41     
     42     if [ -f ${BB_TMPFILE} ];  then
     43         for i in `cat ${BB_TMPFILE}`; do
     44             is_alive=`ps ax | grep "^${i} " | wc -l`
     45             if [ $((${is_alive})) -gt 0 ]; then
     46                 kill -9 ${i}
     47             fi
     48         done
     49         rm ${BB_TMPFILE}; touch ${BB_TMPFILE}
     50     fi
     51 
     52 }
     53 
     54 check_active(){
     55 
     56     ALIVE=0
     57     if [ -f ${BB_TMPFILE} ];  then
     58         for i in `cat ${BB_TMPFILE}`; do
     59             is_alive=`ps ax | grep "^${i} " | wc -l`
     60             if [ $((${is_alive})) -gt 0 ]; then
     61                 ALIVE=1
     62             fi
     63         done
     64         if [ ${ALIVE} -ge 1 ]; then 
     65             return 1;
     66         else
     67             return 0;
     68         fi
     69     else
     70         return 0
     71     fi
     72     
     73     
     74 }
     75 
     76 
     77 
     78 start_bb(){
     79 
     80     check_active
     81     if [ $? != 0 ]; then
     82         echo "beep_boot is already running"
     83         exit 1;
     84     fi
     85 
     86 
     87     rm_hanging_instances 
     88     nohup ${BB_SCRIPTFILE}  2>&1 >/dev/null &
     89     exit 0;
     90 }
     91 
     92 stop_bb(){
     93     check_active 
     94     if [ $? == 0 ]; then
     95         echo "beep_boot is not running"
     96         rm ${BB_TMPFILE}
     97         exit 1;
     98     fi
     99 
    100     rm_hanging_instances
    101     exit 0;
    102 }
    103 
    104 
    105 
    106 
    107 case $1 in 
    108 
    109     start)
    110         start_bb
    111         exit 0;
    112         ;;
    113     
    114     stop)
    115         stop_bb;
    116         exit 0;
    117         ;;
    118     
    119     status)
    120         check_active
    121         if [ $? == 0 ]; then
    122             echo "boot_beep is not up"
    123         else
    124             echo "boot_beep is up and running"
    125         fi
    126         exit 0
    127         ;;
    128 
    129     *)
    130         echo "Usage: $0 {start|stop|status}"
    131         exit 1;
    132 esac