diff options
author | Timo Teras <timo.teras@iki.fi> | 2009-05-15 09:42:43 +0300 |
---|---|---|
committer | Timo Teras <timo.teras@iki.fi> | 2009-05-15 09:42:43 +0300 |
commit | 9f99c5f7723b6e097647df6871797db42f09ad85 (patch) | |
tree | cf1e8741ce93cdf5602c4307170a29dc29639fcc | |
parent | 8fc857f44a02f0425e4640ebdf8542482ab18595 (diff) | |
download | alpine_aports-9f99c5f7723b6e097647df6871797db42f09ad85.tar.bz2 alpine_aports-9f99c5f7723b6e097647df6871797db42f09ad85.tar.xz alpine_aports-9f99c5f7723b6e097647df6871797db42f09ad85.zip |
extra/asterisk: 1.6.0.9 stable
-rw-r--r-- | extra/asterisk/100-uclibc-daemon.patch | 44 | ||||
-rw-r--r-- | extra/asterisk/101-caps-uclibc.patch | 17 | ||||
-rw-r--r-- | extra/asterisk/102-gsm-pic.patch | 54 | ||||
-rw-r--r-- | extra/asterisk/APKBUILD | 92 | ||||
-rw-r--r-- | extra/asterisk/asterisk.confd | 91 | ||||
-rw-r--r-- | extra/asterisk/asterisk.initd | 245 | ||||
-rw-r--r-- | extra/asterisk/asterisk.post-install | 11 | ||||
-rw-r--r-- | extra/asterisk/asterisk.pre-install | 9 |
8 files changed, 563 insertions, 0 deletions
diff --git a/extra/asterisk/100-uclibc-daemon.patch b/extra/asterisk/100-uclibc-daemon.patch new file mode 100644 index 0000000000..4956791d4d --- /dev/null +++ b/extra/asterisk/100-uclibc-daemon.patch | |||
@@ -0,0 +1,44 @@ | |||
1 | diff -Nru asterisk-1.6.1-beta4.org/main/asterisk.c asterisk-1.6.1-beta4/main/asterisk.c | ||
2 | --- asterisk-1.6.1-beta4.org/main/asterisk.c 2008-12-12 23:05:58.000000000 +0100 | ||
3 | +++ asterisk-1.6.1-beta4/main/asterisk.c 2008-12-23 15:28:21.000000000 +0100 | ||
4 | @@ -3295,9 +3295,40 @@ | ||
5 | #if HAVE_WORKING_FORK | ||
6 | if (ast_opt_always_fork || !ast_opt_no_fork) { | ||
7 | #ifndef HAVE_SBIN_LAUNCHD | ||
8 | +#ifndef __UCLIBC__ | ||
9 | if (daemon(1, 0) < 0) { | ||
10 | ast_log(LOG_ERROR, "daemon() failed: %s\n", strerror(errno)); | ||
11 | } | ||
12 | +#else | ||
13 | + /* | ||
14 | + * workaround for uClibc-0.9.29 mipsel bug: | ||
15 | + * recursive mutexes do not work if uClibc daemon() function has been called, | ||
16 | + * if parent thread locks a mutex | ||
17 | + * the child thread cannot acquire a lock with the same name | ||
18 | + * (same code works if daemon() is not called) | ||
19 | + * but duplication of uClibc daemon.c code in here does work. | ||
20 | + */ | ||
21 | + int fd; | ||
22 | + switch (fork()) { | ||
23 | + case -1: | ||
24 | + exit(1); | ||
25 | + case 0: | ||
26 | + break; | ||
27 | + default: | ||
28 | + _exit(0); | ||
29 | + } | ||
30 | + if (setsid() == -1) | ||
31 | + exit(1); | ||
32 | + if (fork()) | ||
33 | + _exit(0); | ||
34 | + if ((fd = open("/dev/null", O_RDWR, 0)) != -1) { | ||
35 | + dup2(fd, STDIN_FILENO); | ||
36 | + dup2(fd, STDOUT_FILENO); | ||
37 | + dup2(fd, STDERR_FILENO); | ||
38 | + if (fd > 2) | ||
39 | + close(fd); | ||
40 | + } | ||
41 | +#endif | ||
42 | ast_mainpid = getpid(); | ||
43 | /* Blindly re-write pid file since we are forking */ | ||
44 | unlink(ast_config_AST_PID); | ||
diff --git a/extra/asterisk/101-caps-uclibc.patch b/extra/asterisk/101-caps-uclibc.patch new file mode 100644 index 0000000000..1acf87f34f --- /dev/null +++ b/extra/asterisk/101-caps-uclibc.patch | |||
@@ -0,0 +1,17 @@ | |||
1 | --- asterisk-1.6.0-beta7.1/configure.ac.orig 2008-04-04 07:31:06 +0000 | ||
2 | +++ asterisk-1.6.0-beta7.1/configure.ac 2008-04-04 07:36:14 +0000 | ||
3 | @@ -522,9 +522,11 @@ | ||
4 | |||
5 | AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h]) | ||
6 | |||
7 | -if test "x${host_os}" = "xlinux-gnu" ; then | ||
8 | - AST_EXT_LIB_CHECK([CAP], [cap], [cap_from_text], [sys/capability.h]) | ||
9 | -fi | ||
10 | +case "${host_os}" in | ||
11 | + linux*) | ||
12 | + AST_EXT_LIB_CHECK([CAP], [cap], [cap_from_text], [sys/capability.h]) | ||
13 | + ;; | ||
14 | +esac | ||
15 | |||
16 | # BSD might not have exp2, and/or log2 | ||
17 | AST_EXT_LIB_CHECK([EXP2L], [m], [exp2l]) | ||
diff --git a/extra/asterisk/102-gsm-pic.patch b/extra/asterisk/102-gsm-pic.patch new file mode 100644 index 0000000000..71370ec0b7 --- /dev/null +++ b/extra/asterisk/102-gsm-pic.patch | |||
@@ -0,0 +1,54 @@ | |||
1 | --- a/codecs/gsm/Makefile.org 2008-03-29 11:33:09.000000000 +0100 | ||
2 | +++ b/codecs/gsm/Makefile 2008-03-29 11:44:40.000000000 +0100 | ||
3 | @@ -37,23 +37,6 @@ | ||
4 | ######### ppro's, etc, as well as the AMD K6 and K7. The compile will | ||
5 | ######### probably require gcc. | ||
6 | |||
7 | -ifeq (, $(findstring $(OSARCH) , Darwin SunOS )) | ||
8 | -ifeq (, $(findstring $(PROC) , x86_64 amd64 ultrasparc sparc64 arm armv5b armeb ppc powerpc ppc64 ia64 s390 bfin mipsel mips)) | ||
9 | -ifeq (, $(findstring $(shell uname -m) , ppc ppc64 alpha armv4l s390 )) | ||
10 | -OPTIMIZE+=-march=$(PROC) | ||
11 | -endif | ||
12 | -endif | ||
13 | -endif | ||
14 | - | ||
15 | -#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only. | ||
16 | -#This works for even old (2.96) versions of gcc and provides a small boost either way. | ||
17 | -#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it. | ||
18 | -#So we go lowest common available by gcc and go a step down, still a step up from | ||
19 | -#the default as we now have a better instruction set to work with. - Belgarath | ||
20 | -ifeq ($(PROC),ultrasparc) | ||
21 | -OPTIMIZE+=-mcpu=v8 -mtune=$(PROC) -O3 | ||
22 | -endif | ||
23 | - | ||
24 | PG = | ||
25 | #PG = -g -pg | ||
26 | ######### Profiling flags. If you don't know what that means, leave it blank. | ||
27 | @@ -208,12 +191,10 @@ | ||
28 | # XXX Keep a space after each findstring argument | ||
29 | # XXX should merge with GSM_OBJECTS | ||
30 | ifeq ($(OSARCH),linux-gnu) | ||
31 | -ifeq (,$(findstring $(shell uname -m) , x86_64 amd64 ppc ppc64 alpha armv4l sparc64 parisc s390 )) | ||
32 | -ifeq (,$(findstring $(PROC) , arm armv5b armeb powerpc ia64 s390 bfin mipsel mips )) | ||
33 | +ifneq ($(K6OPT),) | ||
34 | GSM_SOURCES+= $(SRC)/k6opt.s | ||
35 | endif | ||
36 | endif | ||
37 | -endif | ||
38 | |||
39 | TOAST_SOURCES = $(SRC)/toast.c \ | ||
40 | $(SRC)/toast_lin.c \ | ||
41 | @@ -260,12 +241,10 @@ | ||
42 | $(SRC)/table.o | ||
43 | |||
44 | ifeq ($(OSARCH),linux-gnu) | ||
45 | -ifeq (,$(findstring $(shell uname -m) , x86_64 amd64 ppc ppc64 alpha armv4l sparc64 parisc )) | ||
46 | -ifeq (,$(findstring $(PROC) , arm armv5b armeb powerpc ia64 bfin mipsel mips )) | ||
47 | +ifneq ($(K6OPT),) | ||
48 | GSM_OBJECTS+= $(SRC)/k6opt.o | ||
49 | endif | ||
50 | endif | ||
51 | -endif | ||
52 | |||
53 | TOAST_OBJECTS = $(SRC)/toast.o \ | ||
54 | $(SRC)/toast_lin.o \ | ||
diff --git a/extra/asterisk/APKBUILD b/extra/asterisk/APKBUILD new file mode 100644 index 0000000000..f35676aee7 --- /dev/null +++ b/extra/asterisk/APKBUILD | |||
@@ -0,0 +1,92 @@ | |||
1 | # Contributor: Timo Teras <timo.teras@iki.fi> | ||
2 | # Maintainer: Timo Teras <timo.teras@iki.fi> | ||
3 | pkgname=asterisk | ||
4 | pkgver=1.6.0.9 | ||
5 | pkgrel=0 | ||
6 | pkgdesc="Asterisk: A Module Open Source PBX System" | ||
7 | url="http://www.asterisk.org/" | ||
8 | license="GPL" | ||
9 | depends="ncurses popt zlib newt dahdi-linux dahdi-tools libltdl libpri freetds" | ||
10 | makedepends="autoconf automake libtool ncurses-dev popt-dev newt-dev zlib-dev | ||
11 | postgresql-dev unixodbc-dev dahdi-tools-dev libpri-dev g++ tar | ||
12 | freetds-dev" | ||
13 | install="$pkgname.pre-install $pkgname.post-install" | ||
14 | subpackages="$pkgname-dev $pkgname-doc $pkgname-pgsql $pkgname-odbc | ||
15 | $pkgname-tds" | ||
16 | source="http://downloads.digium.com/pub/asterisk/releases/$pkgname-$pkgver.tar.gz | ||
17 | 100-uclibc-daemon.patch | ||
18 | 101-caps-uclibc.patch | ||
19 | 102-gsm-pic.patch | ||
20 | asterisk.pre-install | ||
21 | asterisk.post-install | ||
22 | asterisk.initd | ||
23 | asterisk.confd" | ||
24 | |||
25 | build() { | ||
26 | cd "$srcdir/$pkgname-$pkgver" | ||
27 | for i in ../[1-9]*.patch; do | ||
28 | msg "Apply $i" | ||
29 | patch -p1 < $i || return 1 | ||
30 | done | ||
31 | |||
32 | sed -i -e 's/PBX_ICONV=1/PBX_ICONV=0/g' configure.ac | ||
33 | |||
34 | ./bootstrap.sh | ||
35 | ./configure --prefix=/usr \ | ||
36 | --sysconfdir=/etc \ | ||
37 | --mandir=/usr/share/man \ | ||
38 | --infodir=/usr/share/info \ | ||
39 | --libdir=/usr/lib \ | ||
40 | --localstatedir=/var \ | ||
41 | --disable-xmldoc --with-gsm=internal \ | ||
42 | --without-iconv --with-popt --with-z --with-newt \ | ||
43 | --with-odbc --with-postgres --with-tds \ | ||
44 | --with-dahdi --with-pri --with-tonezone \ | ||
45 | || return 1 | ||
46 | |||
47 | # and figure out which modules to build | ||
48 | rm menuselect.makeopts | ||
49 | make menuselect.makeopts | ||
50 | make -j1 || return 1 | ||
51 | make -j1 DESTDIR="$pkgdir" install | ||
52 | |||
53 | install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname | ||
54 | install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname | ||
55 | } | ||
56 | |||
57 | _find_and_move() { | ||
58 | local pattern="$1" | ||
59 | cd "$pkgdir" || return 1 | ||
60 | find -name "$pattern" -type f | while read f; do | ||
61 | local dest="$subpkgdir/${f%/*}" | ||
62 | mkdir -p "$dest" | ||
63 | mv "$f" "$dest" | ||
64 | done | ||
65 | } | ||
66 | |||
67 | pgsql() { | ||
68 | depends="uclibc asterisk libpq zlib" | ||
69 | install= | ||
70 | _find_and_move '*_pgsql*' | ||
71 | } | ||
72 | |||
73 | odbc() { | ||
74 | depends="uclibc asterisk unixodbc" | ||
75 | install= | ||
76 | _find_and_move '*odbc*' | ||
77 | } | ||
78 | |||
79 | tds() { | ||
80 | depends="uclibc asterisk freetds" | ||
81 | install= | ||
82 | _find_and_move '*_tds*' | ||
83 | } | ||
84 | |||
85 | md5sums="9142461a5ae047a5493bcb610963bc42 asterisk-1.6.0.9.tar.gz | ||
86 | b00c9d98ce2ad445501248a197c6e436 100-uclibc-daemon.patch | ||
87 | 929f740db7043b4553544ebcc7315c91 101-caps-uclibc.patch | ||
88 | 97b39fd9777a2521d4f9f095482b7ac2 102-gsm-pic.patch | ||
89 | b4a97cb1ec3cc3f71a10ce8c067ab430 asterisk.pre-install | ||
90 | 62ecffc90b6714b85f377d1fac73c58b asterisk.post-install | ||
91 | bbcd152417bb7c838b25cb6007db91da asterisk.initd | ||
92 | ed31d7ba37bcf8b0346dcf8593c395f0 asterisk.confd" | ||
diff --git a/extra/asterisk/asterisk.confd b/extra/asterisk/asterisk.confd new file mode 100644 index 0000000000..fe9f138ab7 --- /dev/null +++ b/extra/asterisk/asterisk.confd | |||
@@ -0,0 +1,91 @@ | |||
1 | # | ||
2 | # Additional options for asterisk | ||
3 | # | ||
4 | # see "asterisk -h" for a list of options | ||
5 | # | ||
6 | ASTERISK_OPTS="" | ||
7 | |||
8 | # | ||
9 | # User and group to run asterisk as | ||
10 | # | ||
11 | # Value: double-colon separated list of user and group, or empty to run as root: | ||
12 | # | ||
13 | # | ||
14 | # "asterisk:asterisk" to run as user "asterisk" and group "asterisk" | ||
15 | # "asterisk" to run as user "asterisk" and all groups that user "asterisk" is a member of | ||
16 | # ":asterisk" to run as user "root" and group "asterisk" | ||
17 | # "" to run as user "root" and group "root" | ||
18 | # | ||
19 | ASTERISK_USER="asterisk" | ||
20 | |||
21 | # | ||
22 | # Nicelevel | ||
23 | # | ||
24 | # Set the priority of the asterisk process | ||
25 | # | ||
26 | # Value: (highest) -20..19 (lowest) | ||
27 | # | ||
28 | #ASTERISK_NICE="19" | ||
29 | |||
30 | # | ||
31 | # Wrapper script | ||
32 | # | ||
33 | # Value: yes or no/empty | ||
34 | # | ||
35 | ASTERISK_WRAPPER="no" | ||
36 | |||
37 | ############# Wrapper script settings ############# | ||
38 | |||
39 | # | ||
40 | # Send crash notifications emails to this address | ||
41 | # (needs a working mail service and /usr/sbin/sendmail to do so (e.g. ssmtp)) | ||
42 | # | ||
43 | # Value: Email address or empty to disable | ||
44 | # | ||
45 | #ASTERISK_NOTIFY_EMAIL="root" | ||
46 | |||
47 | # | ||
48 | # Send asterisk's output to this terminal | ||
49 | # | ||
50 | # Value: Full path to device node or a number | ||
51 | # | ||
52 | #ASTERISK_TTY="/dev/tty9" | ||
53 | |||
54 | # | ||
55 | # Start an asterisk console on the terminal specified by ASTERISK_TTY | ||
56 | # | ||
57 | # Warning! Use only for debugging, this is a potential security issue! | ||
58 | # | ||
59 | # Value: yes or no/empty | ||
60 | # | ||
61 | ASTERISK_CONSOLE="no" | ||
62 | |||
63 | # | ||
64 | # Maximum size of core files. | ||
65 | # | ||
66 | # Value: Size in bytes, unlimited for no limit or empty to disable. | ||
67 | # | ||
68 | #ASTERISK_CORE_SIZE="unlimited" | ||
69 | |||
70 | # | ||
71 | # ASTERISK_CORE_DIR | ||
72 | # | ||
73 | # Value: Directory (will be created if non-existant), default is /tmp | ||
74 | # | ||
75 | ASTERISK_CORE_DIR="/var/lib/asterisk/coredump" | ||
76 | |||
77 | # | ||
78 | # Max number of filedescriptors | ||
79 | # | ||
80 | # Value: Number of descriptors | ||
81 | # | ||
82 | #ASTERISK_MAX_FD="1024" | ||
83 | |||
84 | # | ||
85 | # Kill these tasks after asterisk crashed (ASTERISK_WRAPPER=yes only!) | ||
86 | # | ||
87 | # Warning! This will kill _ALL_ tasks with the specified names! | ||
88 | # | ||
89 | # Value: Space separated list of names in double quotes (e.g. "mpg123 mad") | ||
90 | # | ||
91 | #ASTERISK_CLEANUP_ON_CRASH="mpg123 asterisk-mpg123 mad" | ||
diff --git a/extra/asterisk/asterisk.initd b/extra/asterisk/asterisk.initd new file mode 100644 index 0000000000..dc69aacf4f --- /dev/null +++ b/extra/asterisk/asterisk.initd | |||
@@ -0,0 +1,245 @@ | |||
1 | #!/sbin/runscript | ||
2 | |||
3 | opts="${opts} forcestop reload" | ||
4 | |||
5 | is_running() { | ||
6 | if [ -z "$(pidof asterisk)" ]; then | ||
7 | return 1 | ||
8 | else | ||
9 | PID="$(cat /var/run/asterisk/asterisk.pid)" | ||
10 | for x in $(pidof asterisk); do | ||
11 | if [ "${x}" = "${PID}" ]; then | ||
12 | return 0 | ||
13 | fi | ||
14 | done | ||
15 | fi | ||
16 | |||
17 | return 1 | ||
18 | } | ||
19 | |||
20 | asterisk_run_loop() { | ||
21 | local OPTS ARGS MSG NICE="" | ||
22 | local result=0 signal=0 | ||
23 | |||
24 | # default options | ||
25 | OPTS="-f" # don't fork / detach breaks wrapper script... | ||
26 | |||
27 | # filter (redundant) arguments | ||
28 | ARGS="$(echo "${@}" | sed -e "s:-c\|-f::g")" | ||
29 | |||
30 | # mangle yes/no options | ||
31 | ASTERISK_CONSOLE="$(echo ${ASTERISK_CONSOLE} | tr '[:lower:]' '[:upper:]')" | ||
32 | |||
33 | if [ -n "${ASTERISK_CORE_SIZE}" ] && | ||
34 | [ "${ASTERISK_CORE_SIZE}" != "0" ]; then | ||
35 | ulimit -c ${ASTERISK_CORE_SIZE} | ||
36 | |||
37 | if [ -n "${ASTERISK_CORE_DIR}" ] && \ | ||
38 | [ ! -d "${ASTERISK_CORE_DIR}" ] | ||
39 | then | ||
40 | mkdir -m750 -p "${ASTERISK_CORE_DIR}" | ||
41 | |||
42 | if [ -n "${ASTERISK_USER}" ]; then | ||
43 | chown -R "${ASTERISK_USER}" "${ASTERISK_CORE_DIR}" | ||
44 | fi | ||
45 | fi | ||
46 | ASTERISK_CORE_DIR="${ASTERISK_CORE_DIR:-/tmp}" | ||
47 | |||
48 | cd "${ASTERISK_CORE_DIR}" | ||
49 | echo " Core dump size : ${ASTERISK_CORE_SIZE}" | ||
50 | echo " Core dump location : ${ASTERISK_CORE_DIR}" | ||
51 | fi | ||
52 | |||
53 | if [ -n "${ASTERISK_MAX_FD}" ]; then | ||
54 | ulimit -n ${ASTERISK_MAX_FD} | ||
55 | echo " Max open filedescriptors : ${ASTERISK_MAX_FD}" | ||
56 | fi | ||
57 | |||
58 | if [ -n "${ASTERISK_NICE}" ]; then | ||
59 | echo " Nice level : ${ASTERISK_NICE}" | ||
60 | NICE="nice -n ${ASTERISK_NICE} --" | ||
61 | fi | ||
62 | |||
63 | if [ -n "${ASTERISK_NOTIFY_EMAIL}" ]; then | ||
64 | if [ -x /usr/sbin/sendmail ]; then | ||
65 | echo " Email notifications go to : ${ASTERISK_NOTIFY_EMAIL}" | ||
66 | else | ||
67 | echo " Notifications disabled, /usr/sbin/sendmail doesn't exist or is not executable!" | ||
68 | unset ASTERISK_NOTIFY_EMAIL | ||
69 | fi | ||
70 | fi | ||
71 | |||
72 | if [ -n "${ASTERISK_TTY}" ]; then | ||
73 | for x in ${ASTERISK_TTY} \ | ||
74 | /dev/tty${ASTERISK_TTY} \ | ||
75 | /dev/vc/${ASTERISK_TTY} | ||
76 | do | ||
77 | if [ -c "${x}" ]; then | ||
78 | TTY="${x}" | ||
79 | fi | ||
80 | done | ||
81 | [ -n "${TTY}" ] && \ | ||
82 | echo " Messages are sent to : ${TTY}" | ||
83 | fi | ||
84 | |||
85 | if [ "${ASTERISK_CONSOLE}" = "YES" ] && [ -n "${TTY}" ]; then | ||
86 | echo " Starting Asterisk console : ${ASTERISK_CONSOLE}" | ||
87 | OPTS="${OPTS} -c" | ||
88 | fi | ||
89 | |||
90 | OPTS="${OPTS} ${ARGS}" | ||
91 | |||
92 | while :; do | ||
93 | |||
94 | if [ -n "${TTY}" ]; then | ||
95 | /usr/bin/stty -F ${TTY} sane | ||
96 | ${NICE} /usr/sbin/asterisk ${OPTS} >${TTY} 2>&1 <${TTY} | ||
97 | result=$? | ||
98 | else | ||
99 | ${NICE} /usr/sbin/asterisk ${OPTS} &>/dev/null | ||
100 | result=$? | ||
101 | fi | ||
102 | |||
103 | if [ $result -eq 0 ]; then | ||
104 | echo "Asterisk terminated normally" | ||
105 | break | ||
106 | else | ||
107 | if [ $result -gt 128 ]; then | ||
108 | signal=$((result - 128)) | ||
109 | MSG="Asterisk terminated with Signal: $signal" | ||
110 | |||
111 | CORE_TARGET="core-$(date "+%Y%m%d-%h%M%s")" | ||
112 | |||
113 | local CORE_DUMPED=0 | ||
114 | if [ -f "${ASTERISK_CORE_DIR}/core" ]; then | ||
115 | mv "${ASTERISK_CORE_DIR}/core" \ | ||
116 | "${ASTERISK_CORE_DIR}/${CORE_TARGET}" | ||
117 | CORE_DUMPED=1 | ||
118 | |||
119 | elif [ -f "${ASTERISK_CORE_DIR}/core.${PID}" ]; then | ||
120 | mv "${ASTERISK_CORE_DIR}/core.${PID}" \ | ||
121 | "${ASTERISK_CORE_DIR}/${CORE_TARGET}" | ||
122 | CORE_DUMPED=1 | ||
123 | |||
124 | fi | ||
125 | |||
126 | [ $CORE_DUMPED -eq 1 ] && \ | ||
127 | MSG="${MSG}\n\rCore dumped: ${ASTERISK_CORE_DIR}/${CORE_TARGET}" | ||
128 | else | ||
129 | MSG="Asterisk terminated with return code: $result" | ||
130 | fi | ||
131 | |||
132 | # kill left-over tasks | ||
133 | for X in ${ASTERISK_CLEANUP_ON_CRASH}; do | ||
134 | kill -9 $(pidof ${X}); | ||
135 | done | ||
136 | fi | ||
137 | |||
138 | [ -n "${TTY}" ] \ | ||
139 | && echo "${MSG}" >${TTY} \ | ||
140 | || echo "${MSG}" | ||
141 | |||
142 | |||
143 | if [ -n "${ASTERISK_NOTIFY_EMAIL}" ] && \ | ||
144 | [ -x /usr/sbin/sendmail ]; then | ||
145 | echo -e -n "Subject: Asterisk crashed\n\r${MSG}\n\r" |\ | ||
146 | /usr/sbin/sendmail "${ASTERISK_NOTIFY_EMAIL}" | ||
147 | fi | ||
148 | sleep 5 | ||
149 | echo "Restarting Asterisk..." | ||
150 | done | ||
151 | return 0 | ||
152 | } | ||
153 | |||
154 | start() { | ||
155 | local OPTS USER GROUP PID | ||
156 | local tmp x | ||
157 | |||
158 | if [ -n "${ASTERISK_NICE}" ]; then | ||
159 | if [ ${ASTERISK_NICE} -ge -20 ] && \ | ||
160 | [ ${ASTERISK_NICE} -le 19 ]; then | ||
161 | OPTS="--nicelevel ${ASTERISK_NICE}" | ||
162 | else | ||
163 | eerror "Nice value must be between -20 and 19" | ||
164 | return 1 | ||
165 | fi | ||
166 | fi | ||
167 | |||
168 | if [ -n "${ASTERISK_USER}" ]; then | ||
169 | USER=$(echo $ASTERISK_USER | sed 's/:.*//') | ||
170 | GROUP=$(echo $ASTERISK_USER | awk -F: '/.*:.*/ { print $2 }') | ||
171 | if [ -n "${USER}" ]; then | ||
172 | ASTERISK_OPTS="${ASTERISK_OPTS} -U ${USER}" | ||
173 | fi | ||
174 | if [ -n "${GROUP}" ]; then | ||
175 | ASTERISK_OPTS="${ASTERISK_OPTS} -G ${GROUP}" | ||
176 | GROUP=":${GROUP}" # make it look nice... | ||
177 | fi | ||
178 | ebegin "Starting asterisk PBX (as ${USER}${GROUP})" | ||
179 | else | ||
180 | ebegin "Starting asterisk PBX (as root)" | ||
181 | fi | ||
182 | |||
183 | if [ "$(echo ${ASTERISK_WRAPPER} | tr '[:upper:]' '[:lower:]')" != "yes" ]; then | ||
184 | start-stop-daemon --start --exec /usr/sbin/asterisk \ | ||
185 | ${OPTS} -- ${ASTERISK_OPTS} | ||
186 | result=$? | ||
187 | else | ||
188 | asterisk_run_loop ${ASTERISK_OPTS} 2>/dev/null & | ||
189 | result=$? | ||
190 | fi | ||
191 | |||
192 | if [ $result -eq 0 ]; then | ||
193 | # 2 seconds should be enough for asterisk to start | ||
194 | sleep 2 | ||
195 | is_running | ||
196 | result=$? | ||
197 | fi | ||
198 | |||
199 | eend $result | ||
200 | } | ||
201 | |||
202 | forcestop() { | ||
203 | ebegin "Stopping asterisk PBX" | ||
204 | start-stop-daemon --stop --pidfile /var/run/asterisk/asterisk.pid | ||
205 | eend $? | ||
206 | } | ||
207 | |||
208 | stop() { | ||
209 | if ! is_running; then | ||
210 | eerror "Asterisk is not running!" | ||
211 | return 0 | ||
212 | fi | ||
213 | |||
214 | ebegin "Stopping asterisk PBX now" | ||
215 | /usr/sbin/asterisk -r -x "core stop now" &>/dev/null | ||
216 | # Now we have to wait until asterisk has _really_ stopped. | ||
217 | sleep 1 | ||
218 | if is_running; then | ||
219 | einfon "Waiting for asterisk to shutdown ." | ||
220 | local cnt=0 | ||
221 | while is_running; do | ||
222 | cnt=`expr $cnt + 1` | ||
223 | if [ $cnt -gt 60 ] ; then | ||
224 | # Waited 120 seconds now. Fail. | ||
225 | echo | ||
226 | eend 1 "Failed." | ||
227 | return | ||
228 | fi | ||
229 | sleep 2 | ||
230 | echo -n "." | ||
231 | done | ||
232 | echo | ||
233 | fi | ||
234 | eend 0 | ||
235 | } | ||
236 | |||
237 | reload() { | ||
238 | if is_running; then | ||
239 | ebegin "Forcing asterisk to reload configuration" | ||
240 | /usr/sbin/asterisk -r -x "modules reload" &>/dev/null | ||
241 | eend $? | ||
242 | else | ||
243 | eerror "Asterisk is not running!" | ||
244 | fi | ||
245 | } | ||
diff --git a/extra/asterisk/asterisk.post-install b/extra/asterisk/asterisk.post-install new file mode 100644 index 0000000000..fd51c7fa5d --- /dev/null +++ b/extra/asterisk/asterisk.post-install | |||
@@ -0,0 +1,11 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | chown -R asterisk:asterisk /var/*/asterisk | ||
4 | chown -R asterisk:asterisk /etc/asterisk | ||
5 | chmod -R u=rwX,g=rX,o= /etc/asterisk | ||
6 | |||
7 | # set IP ToS | ||
8 | # iptables -A OUTPUT -t mangle -p udp -m udp --dport 5060 -j DSCP --set-dscp 0x28 | ||
9 | #iptables -A OUTPUT -t mangle -p udp -m udp --sport 10000:20000 -j DSCP --set-dscp 0x28 | ||
10 | # more info: http://www.voip-info.org/wiki-Asterisk+non-root | ||
11 | |||
diff --git a/extra/asterisk/asterisk.pre-install b/extra/asterisk/asterisk.pre-install new file mode 100644 index 0000000000..f4724251f3 --- /dev/null +++ b/extra/asterisk/asterisk.pre-install | |||
@@ -0,0 +1,9 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | user=asterisk | ||
4 | home=/var/lib/asterisk | ||
5 | adduser -h $home -s /bin/false -D $user 2>/dev/null | ||
6 | mkdir -p $home | ||
7 | chown $user:$user $home | ||
8 | exit 0 | ||
9 | |||