updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / amule-remote-cvs / amuled
blob083d1d1081edaf468cb1f601b9a65f87652a58a7
1 #!/bin/bash
3 if [ "$(id -u)" != 0 ]
4 then
5 echo "You must be root to start aMule as daemon."
6 exit 2
7 fi
9 # general config
10 USECOLOR="YES"
11 . /etc/conf.d/amule.conf
12 . /etc/rc.d/functions
14 if [ -z $AMULEUSER ]
15 then
16 echo "Unable to run aMule. You must set the user in /etc/conf.d/amule.conf."
17 exit 2
18 elif [[ $AMULEUSER == "root" ]]
19 then
20 echo "Unable to run aMule. You must not run aMule as root."
21 exit 2
24 confdir=$(su -l $AMULEUSER -c "echo ~")/.aMule
25 logfile=$(su -l $AMULEUSER -c "echo ~")/.aMule/amuled.log
26 lockfile=$(su -l $AMULEUSER -c "echo ~")/.aMule/muleLock
28 PID=`pidof -o %PPID /usr/bin/amuled`
30 [ -f $logfile ] && rm -f $logfile
32 case "$1" in
33 start)
34 stat_busy "Starting aMule"
36 if [ -f $lockfile ]
37 then
38 stat_fail
39 echo "Unable to run aMule, it is already running. If you're sure aMule is not already running, you can remove ${lockfile}."
40 exit 2
43 [ ! -d $confdir ] && su -l $AMULEUSER -c "mkdir -p $confdir"
45 [ -z "$PID" ] && su -l $AMULEUSER -c "/usr/bin/amuled -o &> $logfile &"
47 i=0
49 while [ "$i" -lt 20 ]
51 if [ ! -z "$(grep "No other instances are running." $logfile)" ]
52 then
53 add_daemon amule
54 stat_done
55 exit 0
56 elif [ ! -z "$(grep "There seems to be an instance of aMule already running" $logfile)" ]
57 then
58 stat_fail
59 exit 2
60 else
61 i="$(($i+1))"
63 sleep 1
64 done
65 stat_fail
67 stop)
68 stat_busy "Stopping aMule"
69 if [ -f $lockfile ]
70 then
71 [ ! -z "$PID" ] && kill $PID &> /dev/null
72 else
73 stat_fail
74 echo "Unable to stop aMule. It is not running."
75 exit 2
77 if [ $? -gt 0 ]; then
78 stat_fail
79 else
80 rm_daemon amule
81 stat_done
84 restart)
85 $0 stop
86 sleep 1
87 $0 start
90 echo "usage: $0 {start|stop|restart}"
92 esac
93 exit 0