WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Allround init.d script, for everyday use  (Read 2339 times)

Offline lykkedk

  • Full Member
  • ***
  • Posts: 182
Allround init.d script, for everyday use
« on: September 24, 2014, 12:57:04 PM »
Hi all here.

On my journey, through the piCore universe, i was told, that best way to start a daemon, was via an init.d script.
I have been playing, with some small, yet very cool / usefull programs, for my DIY PlayBox.

I have made a "Allround" init script, which i really would like some comments about (Sure there are much room for improvements  8))
OPTION i would like, is :
Start (exec) as user TC

Anyway, i attached some pictures - my playBox, with LCD and IR remote

Regards... Jesper.

Code: [Select]
#!/bin/sh
# init.d start script
#
# Simple allround init.d script
# Inspired from different sources
# Lykkedk 2014
#################################


[ $(id -u) = 0 ] || { echo "must be root" ; exit 1; }

# Subroutine for flashing START
blingstart()
{
printf "[\e[1;31mOK!\033[0m]"
printf " --> $NAME $MSG "
sleep 0.2
printf "\r[\e[1;32mOK!\033[0m]"
printf " --> $NAME $MSG "
sleep 0.2
echo -e "\033[0m"
}
# Subroutine END

# Subroutine for flashing STOP
blingstop()
{
printf "[\e[1;32mOK!\033[0m]"
printf " --> $NAME $MSG "
sleep 0.2
printf "\r[\e[1;31mOK!\033[0m]"
printf " --> $NAME $MSG "
sleep 0.2
echo -e "\033[0m"
}
# Subroutine END

# Variables for handling daemon
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/LCDd
NAME=LCDd
DESC="LCD-proc daemon"
DEFAULTCFG=/home/tc/LCDd.conf

cancel() { echo "$1" >&2; exit 0; };
test ! -r $DEFAULTCFG || . $DEFAULTCFG > /dev/null 2>&1
test -x "$DAEMON" || cancel "$DAEMON does not exist or is not executable."

case "$1" in
start)
        if pidof -o %PPID $NAME > /dev/null; then
        MSG="Is allready started"
        blingstart
        exit 0
        fi
        MSG=Start
        start-stop-daemon --quiet --start --exec $DAEMON
        blingstart

;;
stop)
        if pidof -o %PPID $NAME > /dev/null; then
        MSG=Stop
        start-stop-daemon --quiet --stop --exec $DAEMON
        blingstop
        exit 0
        fi
        MSG="Is not started"
        blingstop
;;

restart)

        MSG=Stop
        start-stop-daemon --quiet --stop --exec $DAEMON
        blingstop

        MSG=Restart
        start-stop-daemon --quiet --start --exec $DAEMON
        blingstart
;;

status)
        if pidof -o %PPID $NAME > /dev/null; then
        MSG="Is started"
        blingstart
        exit 0
        else
        MSG="Is not started"
        blingstop
        exit 1
        fi
;;

*)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
        esac