urbackup_backend/start_urbackup_server
2014-04-05 14:28:38 +02:00

222 lines
6.6 KiB
Bash
Executable File

#!/bin/sh
NAME="urbackup_srv"
BASEDIR=`dirname $0`
PREFIX=`dirname $BASEDIR`
DAEMON=$PREFIX/sbin/urbackup_srv
if ! test -x $DAEMON
then
PREFIX=/usr/local
DAEMON=$PREFIX/sbin/urbackup_srv
if ! test -x $DAEMON
then
PREFIX=/usr
DAEMON=$PREFIX/sbin/urbackup_srv
fi
fi
DAEMON_DIR="/var"
if ! test -f $DAEMON_DIR/urbackup/backup_server.db
then
DAEMON_DIR="$PREFIX/var"
if ! test -f $DAEMON_DIR/urbackup/backup_server.db
then
DAEMON_DIR="/usr/local/var"
if ! test -f $DAEMON_DIR/urbackup/backup_server.db
then
DAEMON_DIR="/var"
if ! test -d $DAEMON_DIR/urbackup
then
DAEMON_DIR="$PREFIX/var"
if ! test -d $DAEMON_DIR/urbackup
then
DAEMON_DIR="/usr/local/var"
if ! test -d $DAEMON_DIR/urbackup
then
DAEMON_DIR="/usr/var"
fi
fi
fi
fi
fi
fi
DAEMON_LIBS="$PREFIX/lib"
PLUGIN_PYCHART="--plugin $DAEMON_LIBS/liburbackupserver_pychart.so"
if ! test -e $DAEMON_LIBS/liburbackupserver_pychart.so
then
PLUGIN_PYCHART=""
fi
PLUGIN_URL="--plugin $DAEMON_LIBS/liburbackupserver_urlplugin.so"
if ! test -e $DAEMON_LIBS/liburbackupserver_urlplugin.so
then
PLUGIN_URL=""
fi
PLUGIN_BDB="--plugin $DAEMON_LIBS/liburbackupserver_bdbplugin.so"
if ! test -e $DAEMON_LIBS/liburbackupserver_bdbplugin.so
then
PLUGIN_BDB=""
fi
PLUGIN_CRYPTO="--plugin $DAEMON_LIBS/liburbackupserver_cryptoplugin.so"
if ! test -e $DAEMON_LIBS/liburbackupserver_cryptoplugin.so
then
PLUGIN_CRYPTO=""
fi
SNAPSHOT_HELPER="$PREFIX/bin/urbackup_snapshot_helper"
if ! test -x $SNAPSHOT_HELPER
then
echo "Info: Snapshot helper not found. Btrfs mode will not work."
fi
DAEMON_PLUGINS="$PLUGIN_BDB $PLUGIN_PYCHART $PLUGIN_URL $PLUGIN_CRYPTO --plugin $DAEMON_LIBS/liburbackupserver_downloadplugin.so --plugin $DAEMON_LIBS/liburbackupserver_fsimageplugin.so --plugin $DAEMON_LIBS/liburbackupserver_httpserver.so --plugin $DAEMON_LIBS/liburbackupserver.so --http_root $DAEMON_DIR/urbackup/www --workingdir $DAEMON_DIR --snapshot_helper $SNAPSHOT_HELPER"
S_DAEMON="--daemon"
print_help()
{
echo "UrBackup server wrapper script. Starts UrBackup Server."
echo "Parameters:"
echo "--fastcgi_port {port} Specifies the port where UrBackup server will listen for FastCGI connections. Default: 55413"
echo "--http_port {port} Specifies the port where UrBackup server will listen for HTTP connections. Default: 55414"
echo "--logfile {file} Specifies the log file name. Default: urbackup.log"
echo "--loglevel {debug|info|warn|error} Specifies the log level. Possible values: debug, info, warn, error. Default: warn"
echo "--no_daemon Do not start as a daemon"
echo "--pidfile {file} Save pid of daemon in file"
echo "--sqlite_tmpdir {tmpdir} Specifies the directory sqlite uses to store temporary tables"
echo "--verify_hashes Verifies a backup"
echo "--remove_unknown Remove unknown backups from storage and internal database"
echo "--reset_pw {pw} Resets the pw"
echo "--cleanup {X} Cleans up X %|M|G|T from backup storage"
echo "--repair_database Tries to repair the database"
echo "--defrag_database Defragments the internal database and deletes the file entry cache"
echo "--export_auth_log Export authentication log"
echo "--broadcast_interfaces List of network interfaces from which to send broadcasts (separated by ,)"
echo "--user Start as specific user (default: urbackup)"
echo ""
echo "Have a nice day!"
exit 0
}
print_version()
{
echo "UrBackup Server v1.4"
echo "Copyright (C) 2011-2013 Martin Raiber"
echo "This is free software; see the source for copying conditions. There is NO"
echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
exit 0
}
RUN_IN_GDB=0
RUN_IN_VALGRIND=0
GETOPT=getopt
if test -x $PREFIX/bin/getopt
then
GETOPT=$PREFIX/bin/getopt
fi
if `$GETOPT -T > /dev/null 2>&1`; [ $? = 4 ]; then
FASTCGI_PORT=55413
HTTP_PORT=55414
LOGFILE="urbackup.log"
LOGLEVEL="warn"
PIDFILE="/var/run/urbackup_srv.pid"
SQLITE_TMPDIR=""
VERIFY_HASHES=""
RESET_PW=""
CLEANUP=""
BROADCAST_INTERFACES=""
URB_USER="urbackup"
TEMP=`$GETOPT -o f:h:l:v -n start_urbackup_server --long version,no_daemon,help,fastcgi_port:,http_port:,logfile:,loglevel:,pidfile:,sqlite_tmpdir:,verify_hashes:,reset_pw:,cleanup:,remove_unknown,cleanup_database,repair_database,broadcast_interfaces:,run_in_gdb,run_in_valgrind,user:,defrag_database,export_auth_log -- "$@"`
eval set -- "$TEMP"
while true ; do
case "$1" in
-f|--fastcgi_port) FASTCGI_PORT="$2"; shift 2 ;;
-h|--http_port) HTTP_PORT="$2"; shift 2 ;;
-l|--logfile) LOGFILE="$2"; shift 2 ;;
-v|--loglevel) LOGLEVEL="$2"; shift 2 ;;
--pidfile) PIDFILE="$2"; shift 2 ;;
--no_daemon) S_DAEMON=""; shift ;;
--help) print_help ;;
--version) print_version ;;
--sqlite_tmpdir) SQLITE_TMPDIR="--sqlite_tmpdir $2"; shift 2 ;;
--verify_hashes) VERIFY_HASHES="--verify_hashes $2"; shift 2 ;;
--reset_pw) RESET_PW="--reset_pw \"$2\""; shift 2 ;;
--cleanup) CLEANUP="--app cleanup --cleanup_amount $2"; shift 2;;
--remove_unknown) CLEANUP="--app remove_unknown"; shift ;;
--cleanup_database) CLEANUP="--app cleanup_database"; shift ;;
--repair_database) CLEANUP="--app repair_database"; shift ;;
--broadcast_interfaces) BROADCAST_INTERFACES="--broadcast_interfaces \"$2\""; shift 2 ;;
--run_in_gdb) RUN_IN_GDB=1; shift ;;
--run_in_valgrind) RUN_IN_VALGRIND=1; shift ;;
--user) URB_USER="$2"; shift 2;;
--defrag_database) CLEANUP="--app defrag_database"; shift ;;
--export_auth_log) CLEANUP="--app export_auth_log"; shift ;;
--) shift; break ;;
*) echo "error!" ; exit 1 ;;
esac
done
if [ "x$VERIFY_HASHES" != "x" ]
then
LOGLEVEL="info"
S_DAEMON="--no-server"
fi
if [ "x$RESET_PW" != "x" ]
then
LOGLEVEL="debug"
S_DAEMON="--no-server"
fi
if [ "x$CLEANUP" != "x" ]
then
LOGLEVEL="debug"
S_DAEMON="--no-server"
fi
if [ "x$RUN_IN_GDB" = "x1" ]
then
S_DAEMON=""
fi
if [ "x$RUN_IN_VALGRIND" = "x1" ]
then
S_DAEMON=""
fi
DAEMON_ARGS="--port $FASTCGI_PORT --logfile /var/log/$LOGFILE --loglevel $LOGLEVEL --http_port $HTTP_PORT --pidfile $PIDFILE --user $URB_USER $SQLITE_TMPDIR $VERIFY_HASHES $RESET_PW $CLEANUP $BROADCAST_INTERFACES"
else
DAEMON_ARGS="--user urbackup $*"
fi
# Exit if the package is not installed
if [ ! -x $DAEMON ]
then
echo "Server binary not found"
fi
ulimit -n 100000 > /dev/null 2>&1
export MPLCONFIGDIR=$DAEMON_DIR/urbackup
DAEMON_ARGS="$DAEMON_PLUGINS $DAEMON_ARGS"
cd $DAEMON_DIR
if [ "x$RUN_IN_GDB" = "x1" ]
then
gdb --args $DAEMON $S_DAEMON $DAEMON_ARGS
elif [ "x$RUN_IN_VALGRIND" = "x1" ]
then
valgrind --leak-check=full --track-origins=yes $DAEMON $S_DAEMON $DAEMON_ARGS --allow_shutdown true --leak_check true
else
exec $DAEMON $S_DAEMON $DAEMON_ARGS
fi