tifoski
(usa openSUSE)
Enviado em 05/09/2013 - 09:13h
Cara, consegui criar o script. Está funcionando belezinha e sem problemas. Segue o mesmo para que se alguém precisar, utilize-o como base:
1 ### BEGIN INIT INFO
2 # Provides: TRANSX
3 # Required-Start: $syslog $remote_fs
4 # Required-Stop: $syslog
5 # Default-Start: 3 5
6 # Default-Stop:
7 # Description: Servico TRANSX
8 ### END INIT INFO
9
10 SERV=transx
11 APPPATH="/transx/recargametro"
12 JAVA_BIN="/root/jdk1.7.0_25/bin/java"
13
14 PAYLOAD="transx-1.0.103.jar"
15 PIDFILE="/var/run/$SERV.pid"
16
17
18 start() {
19 echo -n "Starting $SERV: "
20 if [ -f $PIDFILE ]; then
21 PID=`cat $PIDFILE`
22 echo $SERV already running $PID
23 exit 2;
24 else
25
26 cd $APPPATH
27
28 $JAVA_BIN -jar $PAYLOAD &> log/Saida.txt &
29 PID=`echo $!`
30 echo $PID > $PIDFILE
31 RETVAL=$?
32 [ $RETVAL -eq 0 ]
33 #echo `ps aux | grep "$PAYLOAD" | grep -v grep | awk {'print $2'}` > $PIDFILE
34 echo OK
35 return $RETVAL
36 fi
37 }
38
39 stop() {
40 echo -n "Stopping $SERV: "
41 if [ -f $PIDFILE ]; then
42 PID=`cat $PIDFILE`
43 kill $PID
44 rm -f $PIDFILE
45 #echo kill $PID rm -f $PIDFILE
46 echo OK
47 return 0
48 else
49 echo "not running or pid file is gone."
50 fi
51 }
52
53 status() {
54 if [ -f $PIDFILE ]; then
55 PID=`cat $PIDFILE`
56 echo "running at PID" $PID.
57 return 0
58 else
59 echo "not running"
60 return 1
61 fi
62 }
63
64 case "$1" in
65 start)
66 start
67 ;;
68 stop)
69 stop
70 ;;
71 status)
72 status
73 ;;
74 restart)
75 stop
76 start
77 ;;
78 *)
79 echo "Usage: {start|stop|restart}"
80 exit 1
81 ;;
82 esac
83
84 exit $?