File: svinitd

package info (click to toggle)
svtools 0.6-2
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 128 kB
  • ctags: 27
  • sloc: sh: 955; makefile: 88
file content (138 lines) | stat: -rwxr-xr-x 2,693 bytes parent folder | download | duplicates (2)
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
#!/bin/sh
#
# svinitd
# init.d wrapper for daemontools services
# Klaus Reimer <k@ailis.de>

if [ "$INIT_VERSION" != "" ]
then
  exit 0
fi

TITLE=svinitd
VERSION=0.6
AUTHOR="Klaus Reimer"
EMAIL=k@ailis.de
COPYRIGHT="Copyright (C) 2000-2011 by $AUTHOR"

showHelp() {
  echo "Usage: $TITLE [OPTION]... SERVICE CMD"
  echo "init.d wrapper for daemontools services"
  echo ""
  echo "  -h, --help     Display help and exit"
  echo "  -V, --version  Display version and exit"
  echo ""
  echo "This utility is an init.d wrapper. You can use this tool"
  echo "to translate init.d commands (like stop, start, restart...) to svc"
  echo "commands. This tool is intended to be used in an init.d script."
  echo ""
  echo "Report bugs to $AUTHOR <$EMAIL>"
}

showVersion() {
  echo "$TITLE $VERSION"
  echo ""
  echo "$COPYRIGHT"
  echo "This is free software; you can redistribute it and/or modify it under"
  echo "the terms of the GNU General Public License as published by the Free"
  echo "Software Foundation; either version 2 of the License, or (at your"
  echo "option) any later version."
}

while getopts "hV-:" NAME
do
  case "$NAME" in
    h)
      showHelp
      exit 0
      ;;
    V)
      showVersion
      exit 0
      ;;
    -)
      case "$OPTARG" in
        help)
          showHelp
          exit 0
          ;;
        version)
          showVersion
          exit 0
          ;;
        *)
          echo "Unknown option: $OPTARG"
          showHelp
          exit 1
      esac  
      ;;
    *)
      echo "Unknown option: $OPTARG"
      showHelp
      exit 1
  esac
done

shift `expr $OPTIND - 1`

if [ $# -ne 2 ]
then
  showHelp
  exit 1
fi

if ! SVDIR=`svdir 2>&1`
then
  echo "$TITLE: $SVDIR" >&2
  exit 1
fi

SERVICE=$1

svok $SVDIR/$SERVICE || exit 1

COMMAND=$2

case "$COMMAND" in
  start)
    echo -n "Starting supervised $SERVICE... "
    svc -u $SVDIR/$SERVICE
    echo "Done"
    ;;
  stop)
    echo -n "Stopping supervised $SERVICE... "
    svc -d $SVDIR/$SERVICE
    echo "Done"
    ;;
  reload)
    echo -n "Reloading supervised $SERVICE... "
    svc -h $SVDIR/$SERVICE
    echo "Done"
    ;;
  restart)
    echo -n "Restarting supervised $SERVICE... "
    svc -t $SVDIR/$SERVICE
    echo "Done"
    ;;
  force-reload)
    echo -n "Force-reloading supervised $SERVICE... "
    svc -k $SVDIR/$SERVICE
    echo "Done"
    ;;
  enable)
    echo -n "Enabling supervised $SERVICE... "
    rm -f $SVDIR/$SERVICE/down
    echo "Done"
    ;;
  disable)
    echo -n "Disabling supervised $SERVICE... "
    touch $SVDIR/$SERVICE/down
    echo "Done"
    ;;
  *)
    echo "$0($SERVICE) {start|stop|reload|restart|force-reload|enable|disable}"
    exit 1
    ;;
esac

exit 0