Ярлыки

Memories ( 25 ) Unix ( 14 ) FreeBSD ( 8 ) www ( 4 ) Scripts ( 3 ) GEOM ( 2 ) PART ( 2 ) smtp ( 2 ) Cacti ( 1 ) Jabber ( 1 ) KVM ( 1 ) Kohana ( 1 ) RAID ( 1 ) Sip ( 1 ) Ubuntu ( 1 ) Zyxel ( 1 ) nginx ( 1 ) php-fpm ( 1 ) portwfd ( 1 ) rewrite ( 1 ) security ( 1 )

Поиск по этому блогу

вторник, 22 февраля 2011 г.

Rtorrent Auto start&restart

Создадим init.d скрипт для автоматического запуска rtorrent

nano /etc/init.d/rtorrent.sh

#!/bin/bash
#
#
# A simple RTorrent initscript for debian-based distros
#
# Distributed as-is, no warranties
#
# Requires GNU Screen
#
# This script does not perform any checks, i.e. wether the user exists, is screen installed etc
#
#
# The user to run rtorrent as
#
RTUSER=enter your username here
#
#
# Paths to different binaries
#
RTORRENT=/usr/bin/rtorrent
#
KILL=/bin/kill
#
SCREEN=/usr/bin/screen
#
#
# PIDfile path
#
PIDFILE=/var/run/rtorrent.pid
#
#
start_rt()
#
{
#
echo -n "Starting rtorrent... "
#
start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --chuid $RTUSER --exec $SCREEN -- -DmUS torrent $RTORRENT
#
if [ $? -eq 0 ]; then
#
echo "success!"
#
echo "To interact with the torrent client, you will need to reattach the screen session with following command:"
#
echo " screen -r torrent"
#
else
#
echo "fail!"
#
fi
#
}
#
#
stop_rt()
#
{
#
echo -n "Stopping rtorrent... "
#
start-stop-daemon --stop --pidfile $PIDFILE
#
if [ $? -eq 0 ]; then
#
echo "The process stopped successfully"
#
else
#
echo "The process failed to stop"
#
fi
#
}
#
#
status_rt()
#
{
#
echo -n "Status: "
#
PID=`cat $PIDFILE`
#
#
# Check if the process with the specified PID exists
#
# kill -0 will return 0 if the process exists
#
$KILL -0 $PID
#
if [ $? -eq 0 ]; then
#
echo "started"
#
return 0
#
else
#
echo "stopped"
#
return 1
#
fi
#
#
}
#
#
restart_rt_if_needeed()
#
{
#
# Seems like Rtorrent sometimes crashes. This function
#
# restarts rtorrent if it's not running
#
status_rt
#
if [ $? -ne 0 ]; then
#
echo "Rtorrent is not running. Restart needed"
#
stop_rt
#
start_rt
#
else
#
echo "Restart is not needed"
#
fi
#
}
#
#
case "$1" in
#
start)
#
start_rt
#
;;
#
stop)
#
stop_rt
#
;;
#
restart)
#
stop_rt
#
start_rt
#
;;
#
restart_if_needed)
#
restart_rt_if_needeed
#
;;
#
status)
#
status_rt
#
;;
#
*)
#
echo "Usage: {start|stop|restart|status|restart_if_needed}"
#
;;
#
esac


chmod 755 /etc/init.d/rtorrent.sh
update-rc.d rtorrent.sh defaults

Комментариев нет :

Отправить комментарий