urbackup_backend/start_urbackup_server
2013-07-28 01:13:39 +02:00

159 lines
4.8 KiB
Bash
Executable File

#!/bin/sh
NAME="urbackup_srv"
PREFIX=/usr
DAEMON=$PREFIX/sbin/urbackup_srv
if ! test -x $DAEMON
then
PREFIX=/usr/local
DAEMON=$PREFIX/sbin/urbackup_srv
fi
DAEMON_DIR="/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
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 "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 --user urbackup --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 ""
echo "Have a nice day!"
exit 0
}
print_version()
{
echo "UrBackup Server v1.3"
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
}
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=""
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 -- "$@"`
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 ;;
--) 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
DAEMON_ARGS="--port $FASTCGI_PORT --logfile /var/log/$LOGFILE --loglevel $LOGLEVEL --http_port $HTTP_PORT --pidfile $PIDFILE $SQLITE_TMPDIR $VERIFY_HASHES $RESET_PW $CLEANUP"
else
DAEMON_ARGS="$*"
fi
# Exit if the package is not installed
if [ ! -x $DAEMON ]
then
echo "Server binary not found"
fi
ulimit -n 10000 > /dev/null 2>&1
export MPLCONFIGDIR=$DAEMON_DIR/urbackup
DAEMON_ARGS="$DAEMON_PLUGINS $DAEMON_ARGS"
cd $DAEMON_DIR
exec $DAEMON $S_DAEMON $DAEMON_ARGS