Make the settings file more like an init.d script, add log rotation support and pidfi...
[gpx-import.git] / settings.sh
1 #!/bin/sh
2
3 # This script configures the environment to use the OSM db
4 # so that the gpx-import program can find it.
5
6 setting () {
7   S_N=GPX_$1
8   shift
9   eval "${S_N}='$*'"
10   export ${S_N}
11 }
12
13 # General settings
14 setting SLEEP_TIME 1
15
16 # Paths (can be relative from invocation path if appropriate)
17 setting PATH_TRACES /home/osm/traces
18 setting PATH_IMAGES /home/osm/images
19 setting PATH_TEMPLATES templates/
20
21 # MySQL connection
22 setting MYSQL_HOST localhost
23 setting MYSQL_USER openstreetmap
24 setting MYSQL_DB openstreetmap
25 setting MYSQL_PASS openstreetmap
26
27 # Logging, pidfiles etc
28 # If you comment out the LOGFILE then it will log to stdout
29 setting LOG_FILE /home/osm/gpx-import.log
30 # If you comment out the PIDFILE then it will not daemonise
31 setting PID_FILE /home/osm/gpx-import.pid
32
33 # Optional debug statements
34 #setting INTERPOLATE_STDOUT 1
35
36 CMD=$1
37 shift
38
39 case "$CMD" in
40     start)
41         if test "x$GPX_PID_FILE" = "x"; then
42             exec "$@"
43         else
44             "$@"
45             $0 check
46         fi
47         ;;
48     stop)
49         if test -r $GPX_PID_FILE; then
50             PID=$(cat $GPX_PID_FILE)
51             if test "x$PID" != "x"; then
52                 if kill -0 $PID; then
53                     kill -TERM $PID
54                     for TRY in $(seq 1 10); do
55                         sleep 1
56                         if ! kill -0 $PID; then
57                             echo "GPX daemon killed"
58                             rm -f $GPX_PID_FILE
59                             exit 0
60                         else
61                             echo "Still running?"
62                         fi
63                     done
64                     echo "GPX daemon still running?"
65                     exit 1
66                 else
67                     echo "GPX daemon is not running, pid ?= $PID"
68                     exit 1
69                 fi
70             else
71                 echo "GPX daemon pidfile is empty"
72                 exit 1
73             fi
74         else
75             echo "GPX daemon pidfile is missing"
76             exit 1
77         fi
78         ;;
79     rotated)
80         if test -r $GPX_PID_FILE; then
81             PID=$(cat $GPX_PID_FILE)
82             if test "x$PID" != "x"; then
83                 if kill -0 $PID; then
84                     kill -HUP $PID
85                     echo "GPX daemon sent HUP"
86                     sleep 0.5
87                     $0 check
88                 else
89                     echo "GPX daemon is not running, pid ?= $PID"
90                 fi
91             else
92                 echo "GPX daemon pidfile is empty"
93             fi
94         else
95             echo "GPX daemon pidfile is missing"
96         fi
97         ;;
98     check)
99         if test -r $GPX_PID_FILE; then
100             PID=$(cat $GPX_PID_FILE)
101             if test "x$PID" != "x"; then
102                 if kill -0 $PID; then
103                     echo "GPX daemon is running, pid = $PID"
104                 else
105                     echo "GPX daemon is not running, pid ?= $PID"
106                     exit 1
107                 fi
108             else
109                 echo "GPX daemon pidfile is empty"
110                 exit 1
111             fi
112         else
113             echo "GPX daemon pidfile is missing"
114             exit 1
115         fi
116         ;;
117     *)
118         echo "usage: $0 [start|stop|rotated|check] path/to/gpx-import"
119         ;;
120 esac