summaryrefslogtreecommitdiff
path: root/network/hiawatha/rc.hiawatha
blob: 06fadff5b6a903982fb98911e2749e265ee1a04c (plain)
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
#!/bin/sh

# Start/stop/restart the hiawatha web server
# Copyright (c) 2009-2012, Antonio Hernández Blas <hba.nihilismus@gmail.com>
# Copyright (c) 2014-2015, Antonio Hernández Blas <hba.nihilismus@gmail.com>

#
#            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
#                    Version 2, December 2004
#
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
#            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
#   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
#  0. You just DO WHAT THE FUCK YOU WANT TO.
#

CONF='/etc/hiawatha'
CMMD="/usr/sbin/hiawatha -c $CONF"

hiawatha_start() {
  if [ -x /usr/sbin/hiawatha ]; then
    if [ -d $CONF ]; then
      PIDOF=$(pgrep -f "$CMMD")
      if [ ! -z "$PIDOF" ]; then
        echo "Error, hiawatha is already running."
      else
        echo "Starting hiawatha:  $CMMD"
        $CMMD
      fi
    else
      echo "Error, directory $CONF does not exist."
    fi
  fi
}

hiawatha_stop() {
  PIDOF=$(pgrep -f "$CMMD")
  if [ -z "$PIDOF" ]; then
    echo "Error, hiawatha is not running."
  else
    echo "Stoping hiawatha:  /bin/kill -s TERM $PIDOF"
    /bin/kill -s TERM $PIDOF
  fi
}

hiawatha_status() {
  PIDOF=$(pgrep -f "$CMMD")
  if [ ! -z "$PIDOF" ]; then
    echo "hiawatha is running."
  else
    echo "hiawatha is not running."
  fi
}

case $1 in
  start)
    hiawatha_start
  ;;
  stop)
    hiawatha_stop
  ;;
  restart)
    hiawatha_stop
    sleep 3
    hiawatha_start
  ;;
  status)
    hiawatha_status
  ;;
  *)
    echo "Usage $0 {start|stop|restart|status}"
    exit 1
  ;;
esac