Tweak databases/cego version 2.20.1
[dports.git] / databases / cego / files / cego.in
1 #!/bin/sh 
2 #
3 # $FreeBSD: head/databases/cego/files/cego.in 340872 2014-01-24 00:14:07Z mat $
4 #
5
6 # PROVIDE: cego
7 # REQUIRE: LOGIN cleanvar
8 # KEYWORD: shutdown
9
10 #
11 # Add the following lines to /etc/rc.conf to enable cego:
12 # cego_enable (bool):      Set to "NO" by default.
13 #                          Set it to "YES" to enable cego
14 # cego_profiles (str):     Set to "" by default.
15 #                          Define your profiles here.
16 # cego_tablespc (str):     Set it to the tablespace
17 # cego_flags (str):        Set to "" by default.
18 #                          Extra flags passed to start command.
19
20 . /etc/rc.subr
21
22 name="cego"
23 rcvar=cego_enable
24
25 command="%%PREFIX%%/bin/cego"
26
27 : ${cego_enable="NO"}
28 : ${cego_conf="%%PREFIX%%/cego"}
29 : ${cego_root="%%PREFIX%%/cego"}
30 : ${cego_user="%%USER%%"}
31
32 flags="--mode=daemon"
33
34 _pidprefix="/var/run/cego"
35 pidfile="${_pidprefix}.pid"
36
37 command_arg="--mode=daemon"
38 _pidprefix="/var/run/cego"
39
40 flags="--mode=daemon"
41
42 load_rc_config $name
43
44 if [ -n "$2" ]; then
45         profile="$2"
46         if [ "x${cego_profiles}" != "x" ]; then
47                 pidfile="${_pidprefix}.${profile}.pid"
48
49                 echo profile is $profile
50
51                 eval cego_tablespc="\${cego_${profile}_tablespc:-}"
52                 if [ "x${cego_tablespc}" = "x" ]; then
53                         err 1 "You must define a tableset for db instance cego_${profile}_tablespc"
54                 fi
55
56                 eval cego_conf="\${cego_${profile}_conf:-${cego_conf}}"
57                 eval cego_root="\${cego_${profile}_root:-${cego_root}}"
58                 
59                 required_files="${cego_conf}/${profile}.xml"
60                 eval cego_enable="\${cego_${profile}_enable:-${cego_enable}}"
61                 command_args="--dbxml=${required_files} --tableset=${cego_tablespc} --lockfile=${cego_root}/${profile}.lck --logfile=${cego_root}/${profile}.log"
62                 echo "Setting command_args $command_args" 
63         else
64                 warn "$0: extra argument ignored"
65         fi
66 else
67         if [ "x${cego_profiles}" != "x" -a "x$1" != "x" ]; then
68                 for profile in ${cego_profiles}; do
69                         eval _enable="\${cego_${profile}_enable}"
70                         case "x${_enable:-${cego_enable}}" in
71                         x|x[Nn][Oo]|x[Nn][Oo][Nn][Ee])
72                                 continue
73                                 ;;
74                         x[Yy][Ee][Ss])
75                                 ;;
76                         *)
77                                 if test -z "$_enable"; then
78                                         _var=cego_enable
79                                 else
80                                         _var=cego_"${profile}"_enable
81                                 fi
82                                 warn "Bad value" \
83                                     "'${_enable:-${cego_enable}}'" \
84                                     "for ${_var}. " \
85                                     "Profile ${profile} skipped."
86                                 continue
87                                 ;;
88                         esac
89                         echo "===> cego profile: ${profile}"
90                         %%PREFIX%%/etc/rc.d/cego $1 ${profile}
91                         retcode="$?"
92                         if [ "0${retcode}" -ne 0 ]; then
93                                 failed="${profile} (${retcode}) ${failed:-}"
94                         else
95                                 success="${profile} ${success:-}"
96                         fi
97                 done
98                 exit 0
99         fi
100 fi
101
102
103 cego_requirepidfile()
104 {
105         if [ ! "0`check_pidfile ${pidfile} ${command}`" -gt 1 ]; then
106                 err 1 "${name} not running? (check $pidfile)."
107         fi
108 }
109
110 run_rc_command "$1"