aboutsummaryrefslogtreecommitdiffstats
path: root/main/zoneminder/zoneminder.initd
blob: 1a34a8914876bcb47116e9a0109cbacce23fcc4d (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/sbin/openrc-run

# init.d file for zoneminder
# Copyright (c) 2013-2016 Kaarle Ritvanen

name=zoneminder
command=/usr/bin/zmpkg.pl
extra_commands="setup perms"

depend() {
	after mariadb
}

start() {
	ebegin "Starting $name"
	if status > /dev/null; then
		ewarn "$name already started"
	else
		prepare
		$command start
	fi
	eend $?
}

stop() {
	ebegin "Stopping $name"
	if status > /dev/null; then
		$command stop
	else
		ewarn "$name already stopped"
	fi
	eend $?
}

status() {
	status=$($command status)
	echo $status
	[ "$status" = running ]
}

setup() {
	. /etc/zm.conf
	ebegin "Initializing $name database"
	mysql -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS \
		< $ZM_PATH_DATA/db/zm_create.sql
	eend $?
}

prepare() {
	. /etc/zm.conf
	install -d -o $ZM_WEB_USER -g $ZM_WEB_GROUP \
		/var/run/zoneminder
	perms simple
}

perms() {
	. /etc/zm.conf
	if [ "$1" != "simple" ]; then
		ebegin "Setting correct permssion, this could take a while"
		RECURSIVE="-R"
	fi
	chown $RECURSIVE $ZM_WEB_USER:$ZM_WEB_GROUP /var/lib/zoneminder/*
	chown $RECURSIVE $ZM_WEB_USER:wheel /var/log/zoneminder
}