TISbackup/scripts/tisbackup_gui

100 lines
2.0 KiB
Plaintext
Raw Normal View History

2015-07-08 17:20:27 +02:00
#!/bin/sh
2013-05-23 10:19:43 +02:00
### BEGIN INIT INFO
2015-07-08 17:20:27 +02:00
# Provides:
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
2013-05-23 10:19:43 +02:00
### END INIT INFO
2015-07-08 17:20:27 +02:00
dir="/opt/tisbackup/"
cmd="python tisbackup_gui.py"
user="root"
2013-05-23 10:19:43 +02:00
2015-07-08 17:20:27 +02:00
name=`basename $0`
pid_file="/var/run/$name.pid"
stdout_log="/var/log/$name.log"
stderr_log="/var/log/$name.err"
2013-05-23 10:19:43 +02:00
2015-07-08 17:20:27 +02:00
get_pid() {
cat "$pid_file"
2013-05-23 10:19:43 +02:00
}
2015-07-08 17:20:27 +02:00
is_running() {
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
}
2013-05-23 10:19:43 +02:00
2015-07-08 17:20:27 +02:00
case "$1" in
start)
if is_running; then
echo "Already started"
else
echo "Starting $name"
cd "$dir"
if [ -z "$user" ]; then
sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
2013-05-23 10:19:43 +02:00
else
2015-07-08 17:20:27 +02:00
sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
2013-05-23 10:19:43 +02:00
fi
2015-07-08 17:20:27 +02:00
echo $! > "$pid_file"
if ! is_running; then
echo "Unable to start, see $stdout_log and $stderr_log"
exit 1
fi
fi
;;
stop)
if is_running; then
echo -n "Stopping $name.."
kill `get_pid`
for i in {1..10}
do
if ! is_running; then
break
fi
2013-05-23 10:19:43 +02:00
2015-07-08 17:20:27 +02:00
echo -n "."
sleep 1
2013-05-23 10:19:43 +02:00
done
2015-07-08 17:20:27 +02:00
echo
2013-05-23 10:19:43 +02:00
2015-07-08 17:20:27 +02:00
if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed"
exit 1
else
echo "Stopped"
if [ -f "$pid_file" ]; then
rm "$pid_file"
fi
fi
else
echo "Not running"
fi
;;
2013-05-23 10:19:43 +02:00
restart)
2015-07-08 17:20:27 +02:00
$0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start
;;
2013-05-23 10:19:43 +02:00
status)
2015-07-08 17:20:27 +02:00
if is_running; then
echo "Running"
else
echo "Stopped"
2013-05-23 10:19:43 +02:00
exit 1
2015-07-08 17:20:27 +02:00
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
2013-05-23 10:19:43 +02:00
esac
2015-07-08 17:20:27 +02:00
2013-05-23 10:19:43 +02:00
exit 0
2015-07-08 17:20:27 +02:00