3
# Provides: solarpowerlog
4
# Required-Start: $remote_fs $syslog $network
5
# Required-Stop: $remote_fs $syslog
6
# Default-Start: 2 3 4 5
8
# Short-Description: Solarpowerlog startup
9
# Description: Solarpowerlog queries solarpower inverters and logs their data
12
# Author: Tobias Frost <tobi@coldtobi.de>
13
# License GPL3 or later
17
# PATH should only include /usr/* if it runs after the mountnfs.sh script
18
PATH=/sbin:/usr/sbin:/bin:/usr/bin
29
PIDFILE=$PIDDIR/$NAME.pid
32
LOGSTD=$LOGDIR/$NAME.log
33
LOGERR=$LOGDIR/$NAME.err
35
SCRIPTNAME=/etc/init.d/$NAME
37
# Exit if the package is not installed
38
[ -x "$DAEMON" ] || exit 0
40
# Read configuration variable file if it is present
41
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
43
# If not enables, do not start
44
[ "x$ENABLED" = "x1" ] || exit 0
46
# Load the VERBOSE setting and other rcS variables
49
# Define LSB log_* functions.
50
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
51
# and status_of_proc is working.
52
. /lib/lsb/init-functions
55
# Function that starts the daemon/service
59
# As we want to run as non-privilegded user, we need to create a helper directory
60
[ ! -e $PIDDIR ] && mkdir -p $PIDDIR && chown $USER $PIDDIR
62
# The same applies to the programm logs. We need to ensure that solarpowerlog can
64
[ ! -e $LOGDIR ] && mkdir -p $LOGDIR && chown $USER $LOGDIR
67
# 0 if daemon has been started
68
# 1 if daemon was already running
69
# 2 if daemon could not be started
70
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
72
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
73
-u $USER -c $USER -g $GROUP -d $RUNDIR -- $DAEMON_ARGS -b \
74
--pidfile $PIDFILE --stdout $LOGSTD --stderr $LOGERR \
80
# Function that stops the daemon/service
85
# 0 if daemon has been stopped
86
# 1 if daemon was already stopped
87
# 2 if daemon could not be stopped
88
# other if a failure occurred
89
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
91
[ "$RETVAL" = 2 ] && return 2
92
# Wait for children to finish too if this is a daemon that forks
93
# and if the daemon is only ever run from this initscript.
94
# If the above conditions are not satisfied then add some other code
95
# that waits for the process to drop all resources that could be
96
# needed by services started subsequently. A last resort is to
97
# sleep for some time.
98
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
99
[ "$?" = 2 ] && return 2
107
# Function that sends a SIGHUP to the daemon/service
111
# If the daemon can reload its configuration without
112
# restarting (for example, when it is sent a SIGHUP),
113
# then implement that here.
115
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
121
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
124
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
125
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
129
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
132
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
133
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
137
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
139
restart|force-reload)
140
log_daemon_msg "Restarting $DESC" "$NAME"
147
1) log_end_msg 1 ;; # Old process is still running
148
*) log_end_msg 1 ;; # Failed to start
158
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2