aboutsummaryrefslogtreecommitdiff
path: root/utils/gpsd/files/gpsd.init
blob: 3271d43fdc1cfaebf26c3d8238ce2e2487a77c6a (plain)
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
#!/bin/sh /etc/rc.common
# Copyright (C) 2009-2011 OpenWrt.org
START=50

USE_PROCD=1
PROG=/usr/sbin/gpsd
NAME=gpsd

validate_section_gpsd()
{
	uci_load_validate gpsd gpsd "$1" "$2" \
		'enabled:bool:1' \
		'device:string' \
		'listen_globally:bool:0' \
		'port:port:2947'
}

gpsd_instance()
{
	[ "$2" = 0 ] || {
		echo "validation failed"
		return 1
	}

	[ "$enabled" = "0" ] && return 1

	procd_open_instance
	procd_set_param command "$PROG" -N -n

	[ "$listen_globally" -ne 0 ] && procd_append_param command -G
	procd_append_param command -S "$port"
	procd_append_param command "$device"
	procd_set_param respawn

	procd_close_instance
}

start_service()
{
	config_load "$NAME"
	config_foreach validate_section_gpsd gpsd gpsd_instance
}

service_triggers() {
	procd_add_reload_trigger "$NAME"
	procd_add_validation validate_section_gpsd
}