Michal Vasko | a53ef88 | 2015-11-24 11:02:01 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # netopeerguid.rc: netopeerguid init script |
| 4 | # Copyright (c) 2006-2015 CESNET, z.s.p.o. |
| 5 | # Author(s): David Kupka <dkupka@cesnet.cz>, Michal Vasko <mvasko@cesnet.cz> |
| 6 | # |
| 7 | # This script is written according to SysV init principles. |
| 8 | # |
| 9 | # To activate this script at the boot time simple copy this file (and |
| 10 | # rename it to 'netopeer' - without any suffix) into the /etc/rc.d/init.d |
| 11 | # directory. Then run chkconfig: |
| 12 | # |
| 13 | # chkconfig --add netopeerguid |
| 14 | # |
| 15 | # Output is logged in /var/log/netopeerguid file. |
| 16 | # |
| 17 | # Two lines below this clause are used by chkconfig(8) to set it to run |
| 18 | # in the boot time. The first of those two lines tells chkconfig what |
| 19 | # runlevels the service should be started in by default, as well as the |
| 20 | # start and stop priority levels. The second line contains a description |
| 21 | # for the service. |
| 22 | # |
| 23 | # chkconfig: 345 50 80 |
| 24 | # description: netopeerguid startup script |
| 25 | |
| 26 | BINDIR="@prefix@/bin/" |
| 27 | LOGFILE="/var/log/netopeerguid" |
| 28 | NPGUID=netopeerguid |
| 29 | |
| 30 | case "$1" in |
| 31 | start ) |
| 32 | echo "== Starting netopeerguid ==" >> $LOGFILE |
| 33 | date >> $LOGFILE |
| 34 | |
| 35 | if [ `ps -C netopeerguid | wc -l` -eq 2 ]; then |
| 36 | echo "Failed: netopeerguid is already running." >> $LOGFILE; |
| 37 | echo "netopeerguid is already running."; |
| 38 | exit 1; |
| 39 | fi |
| 40 | |
| 41 | $BINDIR$NPGUID -d |
| 42 | |
| 43 | # for netopeerguid to start |
| 44 | sleep 1; |
| 45 | |
| 46 | if [ `ps -C netopeerguid | wc -l` -lt 2 ]; then |
| 47 | echo "Failure: netopeerguid failed to start." >> $LOGFILE; |
| 48 | echo "netopeerguid failed to start."; |
| 49 | exit 1; |
| 50 | fi |
| 51 | |
| 52 | echo "== netopeerguid start =="; |
| 53 | echo "Success: netopeerguid started ==" >> $LOGFILE; |
| 54 | ;; |
| 55 | |
| 56 | stop ) |
| 57 | echo "== Stopping netopeerguid ==" >> $LOGFILE |
| 58 | date >> $LOGFILE |
| 59 | |
| 60 | if [ `ps -C netopeerguid | wc -l` -lt 2 ]; then |
| 61 | echo "Failure: netopeerguid is not running." >> $LOGFILE; |
| 62 | echo "netopeerguid is not running."; |
| 63 | exit 1; |
| 64 | fi |
| 65 | |
| 66 | killall -15 netopeerguid |
| 67 | |
| 68 | sleep 2; |
| 69 | |
| 70 | if [ `ps -C netopeerguid | wc -l` -eq 2 ]; then |
| 71 | killall -9 netopeerguid |
| 72 | sleep 1; |
| 73 | |
| 74 | |
| 75 | if [ `ps -C netopeerguid | wc -l` -eq 2 ]; then |
| 76 | echo "Failure: netopeerguid is still running." >> $LOGFILE; |
| 77 | echo "netopeerguid is still running."; |
| 78 | exit 1; |
| 79 | fi |
| 80 | fi |
| 81 | |
| 82 | echo "== netopeerguid stop =="; |
| 83 | echo "Success: netopeerguid stopped ==" >> $LOGFILE; |
| 84 | ;; |
| 85 | |
| 86 | restart|reload ) |
| 87 | $0 stop |
| 88 | $0 start |
| 89 | ;; |
| 90 | |
| 91 | status ) |
| 92 | if [ `ps -C netopeerguid | wc -l` -eq 2 ]; then |
| 93 | echo "netopeerguid is running."; |
| 94 | else |
| 95 | echo "netopeerguid is stopped."; |
| 96 | fi |
| 97 | ;; |
| 98 | * ) |
| 99 | # Display usage of this script |
| 100 | echo "Usage: $0 {start|stop|restart|reload|status}" |
| 101 | ;; |
| 102 | esac |