Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Autoloading services when plugging USB device
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
tojo
n00b
n00b


Joined: 09 Dec 2002
Posts: 72

PostPosted: Mon Dec 08, 2003 8:43 am    Post subject: Autoloading services when plugging USB device Reply with quote

Autoloading services when plugging USB device

I have HP PSC 2110 USB printer and I want to get cups and hpoj services to be started whenever I plug the printer (or put power on). Here is how I achieved this. This is easily modified to any usb device. Pre-requirements are that you have USB correctly setup and emerged hotplug, and usb drivers compiled as modules.

Kernel loads automatically correct usb drivers whenever you plug the device, you should see this from your system log (/var/log/messages or /var/log/everything/current). For me when I plug the printer it loads "printer" driver (module).

So I write little script to file
Code:
/etc/hotplug/usb/printer


Code:
#!/bin/sh

PRG1=/etc/init.d/hpoj
PRG2=/etc/init.d/cupsd

sleep 1
$PRG1 start;
sleep 1;
$PRG2 start;

echo "#!/bin/sh" > $REMOVER
echo "$PRG2 stop" >> $REMOVER
echo "$PRG1 stop" >> $REMOVER
echo "/bin/killall -q -9 ptal-printd" >> $REMOVER
echo "/bin/killall -q -9 ptal-mlcd" >> $REMOVER
echo "/sbin/rmmod printer" >> $REMOVER

chmod +x $REMOVER


And give execution rights to script
Code:
chmod +x /etc/hotplug/usb/printer


And that's it!

Script creates this $REMOVER file (hotplug internal attribute) which is executed when you unplug the printer.

This also works that way if you have hotplug on your system startup (rc-update add hotplug default) this script is executed on system startup if your printer is on.


Update 9.12.2003
Guide to usb-pen/thumbdrive follow this link:
https://listman.redhat.com/archives/rhl-devel-list/2003-August/msg00115.html
Back to top
View user's profile Send private message
tactless
l33t
l33t


Joined: 14 Jul 2002
Posts: 642
Location: Mitzpe Adi, Israel

PostPosted: Sat Jan 31, 2004 9:23 pm    Post subject: Reply with quote

Works well, as long as the printer is not online during startup. If it is, you get depscan.sh errors and the service dependency cache goes a bit funky. Any fix for this?
_________________
Tactless

"If it wasn't for fog, the world would run at a really crappy framerate."

Jabber: tactless@amessage.info
Back to top
View user's profile Send private message
tojo
n00b
n00b


Joined: 09 Dec 2002
Posts: 72

PostPosted: Sat Jan 31, 2004 11:02 pm    Post subject: Reply with quote

Not a fix, but you can start daemons directly. I'm using this script now:
Code:
#!/bin/sh

# Wait device to come up
/bin/sleep 2

# Start necessary services
/bin/nice --adjustment=15 /usr/sbin/ptal-init start -q
/bin/nice --adjustment=15 /usr/sbin/cupsd

if [ ! -e /var/run/usb ]; then
 /bin/mkdir -p /var/run/usb
fi

# Create remover file
echo \
"#!/bin/sh
/bin/killall -q -9 cupsd
/usr/sbin/ptal-init stop -q
/bin/killall -q -9 ptal-printd
/bin/killall -q -9 ptal-mlcd
/bin/sleep 2
/sbin/rmmod usblp
/sbin/rmmod printer
" > $REMOVER

if [ ! -e $REMOVER ]; then
 echo $REMOVER > /tmp/usblp.remover
fi

# Give execute rights to remover
/bin/chmod 0755 $REMOVER
Back to top
View user's profile Send private message
tactless
l33t
l33t


Joined: 14 Jul 2002
Posts: 642
Location: Mitzpe Adi, Israel

PostPosted: Sun Feb 01, 2004 2:26 pm    Post subject: Reply with quote

Come on, that can't possibly be the right way to do it...
Isn't there any way to get around the depscan issue?
_________________
Tactless

"If it wasn't for fog, the world would run at a really crappy framerate."

Jabber: tactless@amessage.info
Back to top
View user's profile Send private message
tactless
l33t
l33t


Joined: 14 Jul 2002
Posts: 642
Location: Mitzpe Adi, Israel

PostPosted: Sun Feb 01, 2004 4:03 pm    Post subject: Reply with quote

Cleaned up a bit (killall cupsd is ugly, and one should wait before killing the ptal scripts)

Code:

#!/bin/sh

/bin/sleep 2

/bin/nice --adjustment=15 /usr/sbin/ptal-init start -q
start-stop-daemon --start --quiet --exec /usr/sbin/cupsd

if [ ! -e /var/run/usb ]; then
        /bin/mkdir -p /var/run/usb
fi

echo \
"#!/bin/sh
start-stop-daemon --stop --quiet --exec /usr/sbin/cupsd
/usr/sbin/ptal-init stop -q
/bin/sleep 2
/bin/killall -q ptal-printd
/bin/killall -q ptal-mlcd
/sbin/rmmod usblp
" > $REMOVER

if [ ! -e $REMOVER ]; then
        echo $REMOVER > /tmp/usblp.remover
fi

/bin/chmod 0755 $REMOVER

_________________
Tactless

"If it wasn't for fog, the world would run at a really crappy framerate."

Jabber: tactless@amessage.info
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum