summaryrefslogtreecommitdiff
path: root/net/quoted/files/quoted.in
blob: 140d7122e15388407b10cb0328eb63791f19be36 (plain) (blame)
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
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: quoted
# REQUIRE: LOGIN
# KEYWORD: shutdown
# AUTHOR:  Bob Frazier

quoted_enable=${quoted_enable:-"NO"}

user="nobody"

. /etc/rc.subr

name="quoted"
rcvar=quoted_enable
command="%%PREFIX%%/bin/${name}"
command_args="-d -p:17"
command_plus_args="${command} ${command_args}"
pidfile="/var/run/${name}.pid"
required_files="%%PREFIX%%/etc/quotes"

start_cmd="${name}_start"
stop_cmd="${name}_stop"

quoted_start()
{
  pid=$(check_pidfile ${pidfile} ${command})
  if [ -z ${pid} ]; then
    if [ -e ${required_files} ] ; then
      ${command_plus_args}
      sleep 1
      pid=`ps ax | awk '{if (match($5, ".*/quoted$") || $5 == "quoted") print $1}`
      if [ -z ${pid} ]; then
        echo "${name} failed to start"
        return 1
      else
        echo ${pid} >${pidfile}
        echo "${name} started."
        pid=$(check_pidfile ${pidfile} ${command})
        if [ -z ${pid} ]; then
          echo "Warning:  pid file ${pidfile} is corrupt."
          echo "The ${name} daemon may not stop properly via the rc.d script."
        fi
        return 0;
      fi
    else
      echo "Required file(s) ${required_files} missing"
    fi
  else
    echo "${name} is already running"
    return 0
    # not an error
  fi

# if I get here something went wrong
  return 2
}

quoted_stop()
{
  pid=$(check_pidfile ${pidfile} ${command})
  if [ -z ${pid} ]; then
    echo ${name} not running?  Check ${pidfile}
    return 1
  fi
  echo "Stopping ${name}"
  kill -${sig_stop:-TERM} ${pid}
  [ $? -ne 0 ] && [ -z "$rc_force" ] && return 1
  wait_for_pids ${pid}
}

load_rc_config $name
run_rc_command "$1"