-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava_daemon_init
More file actions
142 lines (115 loc) · 3.25 KB
/
Copy pathjava_daemon_init
File metadata and controls
142 lines (115 loc) · 3.25 KB
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
135
136
137
138
139
140
141
#! /bin/bash
# Directory where the application resides
DIR=/home/brian/NetBeansProjects/JavaDaemonTemplate
# Application JAR file (may be in a sub folder)
JAR_FILE=$DIR/dist/JavaDaemonTemplate.jar
# The PID file location
PID=/var/run/javadaemon.pid
# JVM in use
JAVA_HOME=/usr/lib/jvm/java-6-sun
# Name of the daemon (will be displayed durning start/stop)
NAME="Java Daemon"
# Main class implementing the Daemon interface
MAIN_CLASS=ke.co.pixie.daemon.JavaDaemon
# Logging properties file
LOG_PROPERTIES_FILE=$DIR/conf/logging.properties
MIN_MEMORY=-Xms256m
MAX_MEMORY=-Xmx512m
# You can enable a security policy if you need it here
#SECURITY_POLICY="-Djava.security.manager -Djava.security.policy=$DIR/daemon.policy"
SECURITY_POLICY=
# Set to 1 to enable debugging
DEBUG=0
DEBUG_OUTPUT_FILE=/home/brian/output.txt
DEBUG_ERROR_FILE=/home/brian/log.txt
# DO NOT EDIT BELOW THIS LINE
usage() {
echo $"Usage: $0 {start|stop|restart} "
return 0
}
start() {
echo $"Starting the $NAME..."
cd $DIR
if [[ $DEBUG -eq 1 ]]; then
jsvc -debug -pidfile $PID -home $JAVA_HOME $SECURITY_POLICY -Djava.util.logging.config.file=$LOG_PROPERTIES_FILE -outfile $DEBUG_OUTPUT_FILE -errfile $DEBUG_ERROR_FILE $MIN_MEMORY $MAX_MEMORY -cp $JAR_FILE $MAIN_CLASS
else
jsvc -pidfile $PID -home $JAVA_HOME $SECURITY_POLICY -Djava.util.logging.config.file=$LOG_PROPERTIES_FILE $MIN_MEMORY $MAX_MEMORY -cp $JAR_FILE $MAIN_CLASS
fi
# Check status of the application
if [[ $? -eq 0 ]]; then
echo $"$NAME Successfully STARTED"
echo
return 0
else
echo $"Failed to START $NAME"
echo
return 1
fi
}
stop() {
echo $"Stopping the $NAME..."
cd $DIR
if [[ $DEBUG -eq 1 ]]; then
jsvc -debug -stop -home $JAVA_HOME -pidfile $PID $SECURITY_POLICY -Djava.util.logging.config.file=$LOG_PROPERTIES_FILE -outfile $DEBUG_OUTPUT_FILE -errfile $DEBUG_ERROR_FILE $MIN_MEMORY $MAX_MEMORY -cp $JAR_FILE $MAIN_CLASS
else
jsvc -stop -home $JAVA_HOME -pidfile $PID $SECURITY_POLICY -Djava.util.logging.config.file=$LOG_PROPERTIES_FILE $MIN_MEMORY $MAX_MEMORY -cp $JAR_FILE $MAIN_CLASS
fi
if [[ -e $PID ]]; then
# Kill the process (so we are sure that it has stopped)
KPID=`cat $PID`
KPID1=$(($KPID - 1))
kill -9 $KPID $KPID1
rm -f $PID
fi
# Check status of the application
if [[ $? -eq 0 ]]; then
echo $"$NAME Successfully STOPPED"
echo
return 0
else
echo $"Failed to STOP $NAME"
echo
return 1
fi
echo
}
restart() {
cd $DIR
stop
sleep 10
if [[ -e $PID ]]; then
# Kill the process (so we are sure that it has stopped)
KPID=`cat $PID`
KPID1=$(($KPID - 1))
kill -9 $KPID $KPID1
rm -f $PID
fi
sleep 2
start
# Check status of the application
if [[ $? -eq 0 ]]; then
echo $"$NAME Successfully RESTARTED"
echo
return 0
else
echo $"Failed to RESTART $NAME"
echo
return 1
fi
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?