updated on Tue Jan 10 12:02:00 UTC 2012
[aur-mirror.git] / mldonkey-cvs / mldonkeyd
blob4e5451fe69786b40c52ed357f62695cea400a1d7
1 #!/bin/bash
3 if [ "$(id -u)" != 0 ] ; then
4 echo "You must be root to start MLDonkey as daemon."
5 exit 2
6 fi
8 # general config
9 USECOLOR="YES"
10 . /etc/conf.d/mldonkey
11 . /etc/rc.d/functions
13 if [ -z $MLDUSER ] ; then
14 echo "Unable to run MLDonkey. You must set a user in /etc/conf.d/mldonkey ."
15 exit 2
18 confdir=$(su $MLDUSER -c 'echo $HOME')/.mldonkey
19 pidfile=${confdir}/mlnet.pid
21 [ -f /tmp/mldonkey.log ] && rm -f /tmp/mldonkey.log
23 case "$1" in
24 start)
25 stat_busy "Starting MLDonkey"
27 [ ! -d $confdir ] && su $MLDUSER -c "mkdir -p $confdir"
29 if [ -f $pidfile ] ; then
30 stat_fail
31 echo "Unable to run MLDonkey, it seems to be already running. If you're sure MLDonkey \
32 is not running, you can remove ${pidfile}."
33 exit 2
34 elif [ -f ${confdir}/config_files_space.tmp ] ; then
35 rm -f ${confdir}/config_files_space.tmp
38 su $MLDUSER -c "/usr/bin/mlnet &> /tmp/mldonkey.log &"
40 i=0
41 while [ "$i" -lt 20 ] ; do
42 if [ ! -z "$(grep "Core started" /tmp/mldonkey.log)" ] ; then
43 add_daemon mldonkey
44 stat_done
45 exit 0
46 elif [ ! -z "$(grep "This means another MLDonkey" /tmp/mldonkey.log)" ] ; then
47 stat_fail
48 exit 2
49 elif [ ! -z "$(grep "This is normally caused by another" /tmp/mldonkey.log)" ] ; then
50 stat_fail
51 exit 2
52 else
53 ((i++))
55 sleep 1
56 done
57 stat_fail
60 stop)
61 stat_busy "Stopping MLDonkey"
62 if [ -f $pidfile ] ; then
63 kill $( cat $pidfile ) &> /dev/null
64 else
65 stat_fail
66 echo "Unable to stop MLDonkey. It is not running."
67 exit 2
70 if [ $? -gt 0 ]; then
71 stat_fail
72 else
73 rm -f $pidfile
74 rm_daemon mldonkey
75 stat_done
79 restart)
80 $0 stop
81 sleep 1
82 $0 start
86 echo "usage: $0 {start|stop|restart}"
88 esac
89 exit 0