Commit cbad924b authored by Aleksy Barcz's avatar Aleksy Barcz

Merge branch 'master' into rc

parents 1d4a4849 ecb65549
# This service file is installed in /etc/systemd/system on purpose,
# so that you may edit this file and a package upgrade
# won't overwrite your custom changes.
[Unit]
Description=Websockify service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
User=root
ExecStart=/usr/bin/websockify 19002 localhost:9002
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
#! /bin/sh
### BEGIN INIT INFO
# Provides: iks
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: SZARP iks system
# Description: Starts all necessary services for szarp-iks system. Right now its websockify only because iks-server has its own init script.
### END INIT INFO
# Author: Jakub Kotur <qba@newterm.pl>
split () {
PATH=/sbin:/usr/sbin:/bin:/usr/bin
cnt=0
tmp_ifs="$1"
index="$2"
string="$3"
IFS=$tmp_ifs
for line in $string; do
if [ $cnt -eq $index ]; then
echo $line
fi
cnt=`expr $cnt + 1`
done
unset IFS
}
get_iks_port () {
PATH=/sbin:/usr/sbin:/bin:/usr/bin
subsection=0
default_port=9002
ini="/etc/szarp/iks-server.ini"
if [ ! -e "$ini" ]; then
echo $default_port
exit 0
fi
while read line; do
prefix=`echo $line | cut -c1`
if [ "$prefix" = "[" ]; then
subsection=1
fi
prefix=`echo $line | cut -c1-4`
if [ "$prefix" = "port" ]; then
if [ $subsection -eq 0 ]; then
port=$(split "=" "1" "$line")
echo $port
exit 0
fi
fi
done < $ini
echo $default_port
}
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="SZARP iks system"
NAME=szarp-iks
PIDFILE=/var/run/$NAME.pid
DAEMON=/usr/bin/websockify
SCRIPTNAME=/etc/init.d/$NAME
CONF_IKS_PORT="$(get_iks_port)"
[ -x "$DAEMON" ] || exit 0
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
. /lib/init/vars.sh
. /lib/lsb/init-functions
: ${WEBSOCKET_PORT:=19002}
: ${IKS_PORT:=$CONF_IKS_PORT}
DAEMON_ARGS="$WEBSOCKET_PORT localhost:$IKS_PORT"
#
# Always be verbose
#
VERBOSE=yes
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --status --quiet --pidfile $PIDFILE \
&& return 1
start-stop-daemon --start -q -b -m -p $PIDFILE --exec $DAEMON -- $DAEMON_ARGS \
|| return 2
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
rm -f $PIDFILE
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
#reload|force-reload)
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:
../services/websockify.service /etc/systemd/system/
#!/bin/sh
systemctl unmask websockify
systemctl enable websockify
systemctl start websockify
#!/bin/sh
systemctl stop websockify
systemctl disable websockify
......@@ -430,7 +430,7 @@ void SaveFile(char * path, int lines, int full, int avg)
// towrite = lines * sizeof(short int);
//} else
// do not write average value
towrite = lines * sizeof(short int);
towrite = (lines - 1) * sizeof(short int);
if (write(fd, buf, towrite) != towrite ) {
char *str;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment