close() file after GET
[krsd] / init-script.sh
1 ### BEGIN INIT INFO
2 # Provides:          rs-serve
3 # Required-Start:    networking
4 # Required-Stop:     networking
5 # Default-Start:     2 3 4 5
6 # Default-Stop:      0 1 6
7 # Short-Description: remotestorage server
8 # Description:       remotestorage-server
9 ### END INIT INFO
10
11 # Using the lsb functions to perform the operations.
12 . /lib/lsb/init-functions
13 # Process name ( For display )
14 NAME=rs-serve
15 # Daemon name, where is the actual executable
16 DAEMON=/usr/bin/rs-serve
17 # pid file for the daemon
18 PIDFILE=/var/run/rs-serve.pid
19
20 # If the daemon is not there, then exit.
21 test -x $DAEMON || exit 5
22
23 . /etc/default/rs-serve
24
25 case $1 in
26  start)
27   # Checked the PID file exists and check the actual status of process
28   if [ -e $PIDFILE ]; then
29    status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?"
30    # If the status is SUCCESS then don't need to start again.
31    if [ $status = "0" ]; then
32     exit # Exit
33    fi
34   fi
35   # Start the daemon.
36   log_daemon_msg "Starting the process" "$NAME"
37   # Start the daemon with the help of start-stop-daemon
38   # Log the message appropriately
39   if start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON -- $OPTIONS ; then
40    log_end_msg 0
41   else
42    log_end_msg 1
43   fi
44   ;;
45  stop)
46   # Stop the daemon.
47   if [ -e $PIDFILE ]; then
48    status_of_proc -p $PIDFILE $DAEMON "Stoppping the $NAME process" && status="0" || status="$?"
49    if [ "$status" = 0 ]; then
50     start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
51     /bin/rm -rf $PIDFILE
52    fi
53   else
54    log_daemon_msg "$NAME process is not running"
55    log_end_msg 0
56   fi
57   ;;
58  restart)
59   # Restart the daemon.
60   $0 stop && sleep 2 && $0 start
61   ;;
62  status)
63   # Check the status of the process.
64   if [ -e $PIDFILE ]; then
65    status_of_proc -p $PIDFILE $DAEMON "$NAME process" && exit 0 || exit $?
66   else
67    log_daemon_msg "$NAME Process is not running"
68    log_end_msg 0
69   fi
70   ;;
71  reload)
72   # Reload the process. Basically sending some signal to a daemon to reload
73   # it configurations.
74   if [ -e $PIDFILE ]; then
75    start-stop-daemon --stop --signal USR2 --quiet --pidfile $PIDFILE --name $NAME
76    log_success_msg "$NAME process reloaded successfully"
77   else
78    log_failure_msg "$PIDFILE does not exists"
79   fi
80   ;;
81  *)
82   # For invalid arguments, print the usage message.
83   echo "Usage: $0 {start|stop|restart|reload|status}"
84   exit 2
85   ;;
86 esac