[packages] polipo: update to v1.0.3, add config and initscript
[packages.git] / net / polipo / files / polipo.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2007 OpenWrt.org
3
4 START=99
5
6 NAME=polipo
7 BIN_F=/usr/sbin/$NAME
8 SSD=start-stop-daemon
9
10 is_enabled() {
11         local cfg="$1"
12
13         config_get_bool enabled "$cfg" enabled '1'
14         [ $enabled -ne 0 ] || {
15                 echo "$initscript: not enabled"
16                 return 1
17         }
18 }
19
20 get_pid_file() {
21         local cfg="$1"
22
23         config_get pid_file "$cfg" pid-file
24         [ -n "$pid_file" ] || pid_file="/var/run/$NAME.pid"
25 }
26
27 get_options() {
28         local cfg="$1"
29
30         config_get options "$cfg" options
31
32         config_get config_file "$cfg" config_file
33         [ -n "$config_script" ] && append options "-c $config_file"
34 }
35
36 start_service() {
37         local cfg="$1"
38
39         is_enabled "$cfg" || return
40         get_pid_file "$cfg"
41         get_options "$cfg"
42
43         $SSD -S -p $pid_file -b -m -x $BIN_F -- $options &>/dev/null
44 }
45
46 stop_service() {
47         local cfg="$1"
48
49         is_enabled "$cfg" || return
50         get_pid_file "$cfg"
51
52         $SSD -K -p $pid_file &>/dev/null
53 }
54
55 start() {
56         config_load $NAME
57         config_foreach start_service $NAME
58 }
59
60 stop() {
61         config_load $NAME
62         config_foreach stop_service $NAME
63 }
64