Tiny Core Extensions > TCE News

Basic init.d script example

<< < (3/4) > >>

curaga:
Added status function example to the script.

bigpcman:

--- Quote from: Jason W on December 02, 2009, 10:23:18 AM ---When extensions contain daemons, it is helpful to provide  an init script to allow the user to start and stop it.  /usr/local/etc/init.d/ is the standard location for extension startup script on TC.  We have the start-stop-daemon in base to make it easy to start and stop processes.  Below is an example of an init script to start and stop rpc.mountd:


--- Code: ---#!/bin/sh
# Starts and stops rpc.mountd
#


case "$1" in
start)

start-stop-daemon --start --exec /usr/local/sbin/portmap -u `id -u`
        start-stop-daemon --start --exec /usr/local/sbin/rpc.mountd

;;

stop)

start-stop-daemon --stop --exec /usr/local/sbin/rpc.mountd
;;

restart)
  $0 stop
  $0 start
;;

status)
             if pidof -o %PPID rpc.mountd > /dev/null; then
                     echo "Running"
                     exit 0
             else
                     echo "Not running"
                     exit 1
             fi
;;

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


--- End code ---

--- End quote ---

It took me awhile to figure out that pidof is not instantaneous for some services. I had to insert a delay to get the correct status of x0vncserver as follows:

--- Code: --- VNCPID=$(pidof x0vncserver)
 sleep 2
 if [ -n "$VNCPID" ]; then
 ....
 else
 ....
  fi
 
--- End code ---

Jason W:
Another way could grep the ps command:


--- Code: ---status)
if ps | awk '{print $3}' | grep -e "/usr/local/sbin/rpc.statd" >/dev/null; then
echo "NFS-client is running."
exit 0
else
echo "NFS-client is not running."
exit 1
fi
;;

--- End code ---

^thehatsrule^:
Keep in mind that grep expects a regex pattern.

Tomaster:
ICT

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version