1#! /bin/sh 2### BEGIN INIT INFO 3# Provides: usbg 4# Required-Start: $local_fs 5# Should-Start: 6# Required-Stop: $local_fs 7# Should-Stop: 8# Default-Start: 2 3 4 5 9# Default-Stop: 0 1 6 10# Short-Description: Example initscript 11# Description: This file should be used to construct scripts to be 12# placed in /etc/init.d 13### END INIT INFO 14 15# PATH should only include /usr/* if it runs after the mountnfs.sh script 16PATH=/sbin:/usr/sbin:/bin:/usr/bin 17 18DESC="Load USB gadget schemas" 19NAME="usbgx" 20DAEMON=/usr/bin/gadget-start 21DAEMON_ARGS="" 22PIDFILE=/var/run/$NAME.pid 23 24. /etc/init.d/functions || exit 1 25 26# Exit if the package is not installed 27[ -x "$DAEMON" ] || exit 0 28 29# Read configuration variable file if it is present 30[ -r /etc/default/$NAME ] && . /etc/default/$NAME 31 32# 33# Function that starts the daemon/service 34# 35do_start() { 36 local status pid 37 38 status=0 39 pid=`pidofproc $NAME` || status=$? 40 case $status in 41 0) 42 echo "$DESC already running ($pid)." 43 exit 1 44 ;; 45 *) 46 echo "Starting $DESC ..." 47 exec $DAEMON $DAEMON_ARGS >/dev/null 2>&1 || status=$? 48 echo "ERROR: Failed to start $DESC." 49 exit $status 50 ;; 51 esac 52} 53 54# 55# Function that stops the daemon/service 56# 57do_stop() { 58 local pid status 59 60 status=0 61 pid=`pidofproc $NAME` || status=$? 62 case $status in 63 0) 64 # Exit when fail to stop, the kill would complain when fail 65 kill -s 15 $pid >/dev/null && rm -f $PIDFILE && \ 66 echo "Stopped $DESC ($pid)." || exit $? 67 ;; 68 *) 69 echo "$DESC is not running; none killed." >&2 70 ;; 71 esac 72 73 return $status 74} 75 76# 77# Function that sends a SIGHUP to the daemon/service 78# 79do_reload() { 80 local pid status 81 82 status=0 83 # If the daemon can reload its configuration without 84 # restarting (for example, when it is sent a SIGHUP), 85 # then implement that here. 86 pid=`pidofproc $NAME` || status=$? 87 case $status in 88 0) 89 echo "Reloading $DESC ..." 90 kill -s 1 $pid || exit $? 91 ;; 92 *) 93 echo "$DESC is not running; none reloaded." >&2 94 ;; 95 esac 96 exit $status 97} 98 99 100# 101# Function that shows the daemon/service status 102# 103status_of_proc () { 104 local pid status 105 106 status=0 107 # pidof output null when no program is running, so no "2>/dev/null". 108 pid=`pidofproc $NAME` || status=$? 109 case $status in 110 0) 111 echo "$DESC is running ($pid)." 112 exit 0 113 ;; 114 *) 115 echo "$DESC is not running." >&2 116 exit $status 117 ;; 118 esac 119} 120 121case "$1" in 122 start) 123 do_start 124 ;; 125 stop) 126 do_stop || exit $? 127 ;; 128 status) 129 status_of_proc 130 ;; 131 restart) 132 # Always start the service regardless the status of do_stop 133 do_stop 134 do_start 135 ;; 136 try-restart|force-reload) 137 do_stop && do_start 138 ;; 139 *) 140 echo "Usage: $0 {start|stop|status|restart|try-restart|force-reload}" >&2 141 exit 3 142 ;; 143esac 144