PDA

View Full Version : Autostart Twonky


Gizmo1007
04-04-2008, 21:19
Hopefully this may be of some use to those of you who use Twonky and have had issues with getting it to autostart on system reboot.

Before this I couldn't get Twonky to autostart i always had to go in and start it.
The following information is based on the latest KC firmware ver 1.0.7.8.
Anyway enough of that on with the code.

I have found version 4.4 of twonky to be problematic, (ie) I couldn't view any divx files however I have found that version 4.2 and v.4.3 work with no issues

You need to create a couple of files.

I am assuming that you have twonkymedia files located in /opt/etc/twonky
adjust the file below as necessary

File 1. /opt/etc/init.d/S82twonky
place code below into this file.


#!/opt/bin/sh

PATH=/opt/bin:/opt/sbin:/usr/sbin:/usr/bin:/sbin:/bin
DAEMON=/opt/etc/twonky/twonkymedia
NAME=ushare
DESC="Twonky UPnP A/V Media Server Version 4.2"
PIDFILE=/var/run/twonky.pid

start() {
if [ -f $PIDFILE ]; then
echo "Warning : $PIDFILE still present. Unclean shutdown ?"
kill -s 9 `cat $PIDFILE` 2>/dev/null
rm -f $PIDFILE 2>/dev/null
fi
echo -n "Starting $DESC... "
$DAEMON
echo "done"
}

stop() {
echo -n "Stopping $DESC... "
if [ -f $PIDFILE ]; then
kill -9 `cat $PIDFILE` 2>/dev/null
killall -9 twonkymediaserver
rm -f $PIDFILE 2>/dev/null
fi
echo "done"
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 1
start
;;
*)
echo "Usage: $0 (start|stop|restart)"
exit 1
;;
esac



Chmod 755 /opt/etc/init.d/S82twonky

next we create the file which crontab will run to check if twonky has been started. This will check if the pid has been put in the /var/run location.
if the file exists then it will simply exit.

File 2. /opt/etc/twonky-autostart.sh


#!/opt/bin/bash

# check for running pid and if not present
# start twonky.
# requires you to have S82twonky in init.d
# put in cron as a job and run every 5 minutes

PIDFILE=/var/run/twonky.pid

if [ -f $PIDFILE ]; then
exit 0;
else
/opt/etc/init.d/S82twonky start
fi



again make sure you chmod 755 twonky-autostart.sh.

Finally

put a check in your crontab to run this every 5 minutes.

like so

*/5 * * * * /opt/etc/twonky-autostart.sh


Giz1007

mumsoft
04-04-2008, 22:04
Hi,

Impressive, but, I have only this in my rc.local: :p

#Start Twonkymedia, before changing library_path
/opt/share/TwonkyMedia/twonkymedia &

and I shut down my Asus every day, and it starts up with Twonky (4.4), no problem. :D
Regarding divx, you probably should remove

MT:avi,divx video/avi :rolleyes:
in the clients.db (in directory resources)

Love,
Marc