blob: fc461ce263f3d40e92d933fb9931b27dba598422 (
plain) (
blame)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#!/bin/bash
set -eo pipefail
name=`rev <<<$1 | cut -d/ -f1 | rev`
SVCNAME=$name
pidfile=/run/user/`id -u`/$name.pid
[ -w /run/user/`id -u`/log ] && stdout_logger="logger --socket /run/user/`id -u`/log" || stdout_logger=logger # failback to logging to syslog
stderr_logger=$stdout_logger
[ -r `sed s,/init.d/,/conf.d/, <<<$1` ] && . `sed s,/init.d/,/conf.d/, <<<$1`
. $1
type eerror > /dev/null 2> /dev/null || eerror() {
echo NAPAKA: $@
}
type ewarn > /dev/null 2> /dev/null || ewarn() {
echo OPOZORILO: $@
}
type einfo > /dev/null 2> /dev/null || einfo () {
echo INFO: $@
}
type ebegin > /dev/null 2> /dev/null || ebegin() {
echo ZAČENJAM: $@
}
type need_net > /dev/null 2> /dev/null || need_net() {
[ `ip a | grep ^[[:digit:]] | wc -l` -gt 1 ] || { eerror "Ni omrežnih vmesnikov poleg lo." && return 1; }
[ `ip route | wc -l` -gt 1 ] || { eerror "Usmerjevalna tabela je prazna." && return 1; }
}
type need_clock > /dev/null 2> /dev/null || need_clock() {
year=`date +%Y`
[ $? -eq 0 ] || { eerror "Ura ne deluje." && return 1; }
[ $year -ge 2024 ] || { eerror "Ura je narobe nastavljena." && return 1; }
}
type need_hostname > /dev/null 2> /dev/null || need_hostname() {
hn=`hostname`
[ $? -eq 0 ] || { eerror "Ni mogoče pridobiti imena gostitelja." && return 1; }
[ x$hn = x ] && { eerror "Ni imena gostitelja" && return 1; }
[ x$hn = xlocalhost ] && { eerror "Ime gostitelja je localhost." && return 1; }
return 0
}
needs=
needs_izpolnjen=0
type need > /dev/null 2> /dev/null || need() {
for i in $@
do
needs="$needs $i"
need_$i || { eerror "Odvisnost $i ni izpolnjena." && needs_izpolnjen=1; }
done
}
provides=
type provide > /dev/null 2> /dev/null || provide() {
for i in $@
do
provides="$provides $i"
done
}
type depend > /dev/null 2> /dev/null || depend() {
return
}
type check_dependencies > /dev/null 2> /dev/null || check_dependencies() {
depend
return $needs_izpolnjen
}
type needs > /dev/null 2> /dev/null || needs() {
depend
echo $needs
}
type provides > /dev/null 2> /dev/null || provides() {
depend
echo $provides
}
type checkconfig > /dev/null 2> /dev/null || checkconfig() {
return
}
type start > /dev/null 2> /dev/null || start() {
checkconfig || { eerror "Checkconfig ni uspel." && return 1; };
check_dependencies || { eerror "Odvisnosti niso izpolnjene."; return 1; }
ebegin "Zaganjam $SVCNAME"
start-stop-daemon --start --verbose `[ x$command_background = true ] || echo --background --make-pidfile` `[ x$chdir = x ] || echo --chdir $chdir` --stdout-logger "$stdout_logger" --stderr-logger "$stderr_logger" --exec $command --pidfile $pidfile -- $command_args || { eerror "start-stop-daemon ni uspel. Koda napake: $?"; return 1; }
}
type stop > /dev/null 2> /dev/null || stop() {
ebegin "Ustavljam $SVCNAME"
start-stop-daemon --stop --pidfile $pidfile --verbose --exec $command -- $command_args || { eerror "start-stop-daemon ni uspel. Koda napake: $?"; return 1; }
}
type restart > /dev/null 2> /dev/null || restart() {
checkconfig || { eerror "Checkconfig ni uspel." && return 1; };
stop || ewarn "Stop ni uspel. Vseeno poskušam zagnati storitev."
start || { eerror "Start ni uspel." && return 1; }
}
type reload > /dev/null 2> /dev/null || reload() {
checkconfig || { eerror "Checkconfig ni uspel." && return 1; };
ebegin "Pošiljam SIGHUP storitvi $SVCNAME"
start-stop-daemon --signal HUP $start_stop_daemon_args
}
type status > /dev/null 2> /dev/null || status() {
if [ -r $pidfile ]
then
if [ -d /proc/`cat $pidfile` ]
then
einfo started
else
einfo crashed
return 3
fi
else
einfo stopped
return 3
fi
}
type list > /dev/null 2> /dev/null || list() {
echo start stop restart $extra_commands $extra_started_commands $extra_stopped_commands status reload list check_dependencies needs provides
}
if type $2 > /dev/null 2> /dev/null
then
${@:2}
else
eerror "Ta ukaz ne obstaja!"
fi
|