| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
####### |
| 4 |
# SPDX license identifier: MPL-2.0 |
| 5 |
# |
| 6 |
# Copyright (C) 2011-2015, BMW AG |
| 7 |
# |
| 8 |
# This file is part of COVESA Project DLT - Diagnostic Log and Trace. |
| 9 |
# |
| 10 |
# This Source Code Form is subject to the terms of the |
| 11 |
# Mozilla Public License (MPL), v. 2.0. |
| 12 |
# If a copy of the MPL was not distributed with this file, |
| 13 |
# You can obtain one at http://mozilla.org/MPL/2.0/. |
| 14 |
# |
| 15 |
# For further information see http://www.covesa.org/. |
| 16 |
####### |
| 17 |
|
| 18 |
### BEGIN INIT INFO |
| 19 |
# Provides: dlt-daemon |
| 20 |
# Required-Start: $network $local_fs |
| 21 |
# Required-Stop: |
| 22 |
# Default-Start: 2 3 4 5 |
| 23 |
# Default-Stop: 0 1 6 |
| 24 |
# Short-Description: <Enter a short description of the sortware> |
| 25 |
# Description: <Enter a long description of the software> |
| 26 |
# <...> |
| 27 |
# <...> |
| 28 |
### END INIT INFO |
| 29 |
|
| 30 |
# Author: root <[email protected]> |
| 31 |
|
| 32 |
# PATH should only include /usr/* if it runs after the mountnfs.sh script |
| 33 |
PATH=/sbin:/usr/sbin:/bin:/usr/bin |
| 34 |
DESC=dlt-daemon # Introduce a short description here |
| 35 |
NAME=dlt-daemon # Introduce the short server's name here |
| 36 |
DAEMON=@CMAKE_INSTALL_PREFIX@/bin/dlt-daemon # Introduce the server's location here |
| 37 |
DAEMON_ARGS="-d" # Arguments to run the daemon with |
| 38 |
PIDFILE=/tmp/dltd.lock # Path is configured with DLT configuration of DLT_USER_DIR/DLT_DAEMON_LOCK_FILE |
| 39 |
SCRIPTNAME=/etc/init.d/$NAME |
| 40 |
|
| 41 |
# Exit if the package is not installed |
| 42 |
[ -x $DAEMON ] || exit 0 |
| 43 |
|
| 44 |
# Read configuration variable file if it is present |
| 45 |
[ -r /etc/default/$NAME ] && . /etc/default/$NAME |
| 46 |
|
| 47 |
# Load the VERBOSE setting and other rcS variables |
| 48 |
. /lib/init/vars.sh |
| 49 |
|
| 50 |
# Define LSB log_* functions. |
| 51 |
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
| 52 |
. /lib/lsb/init-functions |
| 53 |
|
| 54 |
# |
| 55 |
# Function that starts the daemon/service |
| 56 |
# |
| 57 |
do_start() |
| 58 |
{ |
| 59 |
# Return |
| 60 |
# 0 if daemon has been started |
| 61 |
# 1 if daemon was already running |
| 62 |
# 2 if daemon could not be started |
| 63 |
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ |
| 64 |
|| return 1 |
| 65 |
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ |
| 66 |
$DAEMON_ARGS \ |
| 67 |
|| return 2 |
| 68 |
# Add code here, if necessary, that waits for the process to be ready |
| 69 |
# to handle requests from services started subsequently which depend |
| 70 |
# on this one. As a last resort, sleep for some time. |
| 71 |
} |
| 72 |
|
| 73 |
# |
| 74 |
# Function that stops the daemon/service |
| 75 |
# |
| 76 |
do_stop() |
| 77 |
{ |
| 78 |
# Return |
| 79 |
# 0 if daemon has been stopped |
| 80 |
# 1 if daemon was already stopped |
| 81 |
# 2 if daemon could not be stopped |
| 82 |
# other if a failure occurred |
| 83 |
# default: --retry=TERM/30/KILL/5 |
| 84 |
start-stop-daemon --stop --quiet --retry=TERM/1/KILL/1 --pidfile $PIDFILE --name $NAME |
| 85 |
RETVAL="$?" |
| 86 |
[ "$RETVAL" = 2 ] && return 2 |
| 87 |
# Wait for children to finish too if this is a daemon that forks |
| 88 |
# and if the daemon is only ever run from this initscript. |
| 89 |
# If the above conditions are not satisfied then add some other code |
| 90 |
# that waits for the process to drop all resources that could be |
| 91 |
# needed by services started subsequently. A last resort is to |
| 92 |
# sleep for some time. |
| 93 |
# default: --retry=0/30/KILL/5 |
| 94 |
start-stop-daemon --stop --quiet --oknodo --retry=0/1/KILL/1 --exec $DAEMON |
| 95 |
[ "$?" = 2 ] && return 2 |
| 96 |
# Many daemons don't delete their pidfiles when they exit. |
| 97 |
rm -f $PIDFILE |
| 98 |
return "$RETVAL" |
| 99 |
} |
| 100 |
|
| 101 |
# |
| 102 |
# Function that sends a SIGHUP to the daemon/service |
| 103 |
# |
| 104 |
do_reload() { |
| 105 |
# |
| 106 |
# If the daemon can reload its configuration without |
| 107 |
# restarting (for example, when it is sent a SIGHUP), |
| 108 |
# then implement that here. |
| 109 |
# |
| 110 |
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME |
| 111 |
return 0 |
| 112 |
} |
| 113 |
|
| 114 |
case "$1" in |
| 115 |
start) |
| 116 |
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME" |
| 117 |
do_start |
| 118 |
case "$?" in |
| 119 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 120 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 121 |
esac |
| 122 |
;; |
| 123 |
stop) |
| 124 |
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
| 125 |
do_stop |
| 126 |
case "$?" in |
| 127 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 128 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 129 |
esac |
| 130 |
;; |
| 131 |
status) |
| 132 |
if [ -f /var/log/messages ] |
| 133 |
then |
| 134 |
log_daemon_msg "------- messages ----------------" |
| 135 |
cat /var/log/messages | grep -a DLT | tail |
| 136 |
fi |
| 137 |
|
| 138 |
if [ -f /var/log/syslog ] |
| 139 |
then |
| 140 |
log_daemon_msg "------- SYSLOG -------------------" |
| 141 |
cat /var/log/syslog | grep -a DLT | tail |
| 142 |
fi |
| 143 |
|
| 144 |
pidofdlt=`pidof $DESC` |
| 145 |
if [ $pidofdlt ] |
| 146 |
then |
| 147 |
log_daemon_msg "$NAME has the PID:$pidofdlt" |
| 148 |
fi |
| 149 |
|
| 150 |
status_of_proc "$DAEMON" "$NAME" || exit $? |
| 151 |
;; |
| 152 |
#reload|force-reload) |
| 153 |
# |
| 154 |
# If do_reload() is not implemented then leave this commented out |
| 155 |
# and leave 'force-reload' as an alias for 'restart'. |
| 156 |
# |
| 157 |
#log_daemon_msg "Reloading $DESC" "$NAME" |
| 158 |
#do_reload |
| 159 |
#log_end_msg $? |
| 160 |
#;; |
| 161 |
restart|force-reload) |
| 162 |
# |
| 163 |
# If the "reload" option is implemented then remove the |
| 164 |
# 'force-reload' alias |
| 165 |
# |
| 166 |
log_daemon_msg "Restarting $DESC" "$NAME" |
| 167 |
do_stop |
| 168 |
case "$?" in |
| 169 |
0|1) |
| 170 |
do_start |
| 171 |
case "$?" in |
| 172 |
0) log_end_msg 0 ;; |
| 173 |
1) log_end_msg 1 ;; # Old process is still running |
| 174 |
*) log_end_msg 1 ;; # Failed to start |
| 175 |
esac |
| 176 |
;; |
| 177 |
*) |
| 178 |
# Failed to stop |
| 179 |
log_end_msg 1 |
| 180 |
;; |
| 181 |
esac |
| 182 |
;; |
| 183 |
*) |
| 184 |
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 |
| 185 |
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 |
| 186 |
exit 3 |
| 187 |
;; |
| 188 |
esac |
| 189 |
|
| 190 |
: |