-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccws-cleaner
executable file
·134 lines (115 loc) · 3.01 KB
/
ccws-cleaner
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/sh
### BEGIN INIT INFO
# Provides: ccws-cleaner
# Required-Start: ccws-db
# Required-Stop: ccws-db
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: initscript for Charta Caeli web service Cleaner
### END INIT INFO
# Author: #USERNAME# <#EMAIL#>
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Charta Caeli web service Cleaner"
NAME=ccws-cleaner
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-1.8.0-openjdk}
DAEMON_USR=${DAEMON_USR:-ccaeli}
DAEMON_DIR=${DAEMON_DIR:-/opt/chartacaeli/web/WEB-INF}
DAEMON=${DAEMON:-./Cleaner.sh}
DAEMON_CMD=${DAEMON_CMD:-unset LANG ; JAVA=$JAVA_HOME/bin/java LOGLEVEL=1 $DAEMON -i 3600}
PIDFILE=/opt/chartacaeli/$NAME.pid
LOGFILE=/opt/chartacaeli/$NAME.log
SCRIPTNAME=/etc/init.d/$NAME
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
if test -s $PIDFILE ; then
pid=$(cat $PIDFILE)
if test -d /proc/$pid ; then
cat /proc/$pid/cmdline | grep -qs $DAEMON && return 1
else
# remove abandoned PID file
rm -f $PIDFILE
fi
fi
sudo -u $DAEMON_USR -- bash -c "cd $DAEMON_DIR ; $DAEMON_CMD >>$LOGFILE 2>&1 & echo \$! >$PIDFILE"
if test $? -eq 0 ; then
return 0
fi
return 2
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
if test -s $PIDFILE ; then
pid=$(cat $PIDFILE)
if test -d /proc/$pid ; then
cat /proc/$pid/cmdline | grep -qs $DAEMON \
&& { sudo -u $DAEMON_USR -- bash -c "kill $pid ; rm -f $PIDFILE" ; return 0 ; }
else
# remove abandoned PID file
rm -f $PIDFILE
fi
fi
return 1
}
do_status()
{
# Return
# 0 if daemon is running
# 1 if daemon not running
if test -s $PIDFILE ; then
pid=$(cat $PIDFILE)
if test -d /proc/$pid ; then
cat /proc/$pid/cmdline | grep -qs $DAEMON \
&& return 0
else
# remove abandoned PID file
rm -f $PIDFILE
fi
fi
return 1
}
case "$1" in
start)
[ "$VERBOSE" != no ] && echo "Starting $DESC" "$NAME"
do_start
case "$?" in
0) [ "$VERBOSE" != no ] && echo "$NAME : $DAEMON started" ; exit 0 ;;
1) [ "$VERBOSE" != no ] && echo "$NAME : $DAEMON already running" ; exit 0 ;;
2) [ "$VERBOSE" != no ] && echo "$NAME : failed to start $DAEMON" ; exit 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && echo "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0) [ "$VERBOSE" != no ] && echo "$NAME : $DAEMON stopped" ; exit 0 ;;
1) [ "$VERBOSE" != no ] && echo "$NAME : $DAEMON already stopped" ; exit 0 ;;
2) [ "$VERBOSE" != no ] && echo "$NAME : failed to stop $DAEMON" ; exit 1 ;;
esac
;;
status)
do_status && exit 0 || exit $?
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status}" >&2
exit 3
;;
esac