systemd service file


16 posts
by sdjf » Fri Jan 04, 2013 2:37 am
Studying logs, I see that when I put a service file in /etc/systemd/system/multi-user.target.wants/, it runs before it should run. I need it to run after the devices in the USB ports have been mounted and bound to the appropriate drivers.

How do I do that in Arch? It also needs to happen after all different kinds of appropriate networking have finished getting set up by the kernel.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || This Pi owner is running Arch on 512MB Model B.
Posts: 1294
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by Rozan » Thu Jan 10, 2013 10:33 am
What services are you referring to?
Posts: 4
Joined: Fri Dec 28, 2012 1:22 pm
by sdjf » Thu Jan 10, 2013 4:06 pm
Rozan wrote:What services are you referring to?


I have a script that enables my zaurus pda to connect to the pi. calling it from an entry in systemd that I named zaurus.service, but it needs to not run until after the pi has assigned device numbers to all usb devices. script seems to run before that happens so it does not work, may need to put it somewhere else or add some parameter to it that tells it to wait until after some other startup event.

Zaurus is connected to Pi over usb, right now have to manually set ifconfig after usb devices have been evaluated.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || This Pi owner is running Arch on 512MB Model B.
Posts: 1294
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by pepedog » Thu Jan 10, 2013 5:08 pm
You could have a delay, eg in the exec
"sleep 30 && /pathto/othercommand.sh"
Posts: 968
Joined: Fri Oct 07, 2011 9:55 am
by sdjf » Thu Jan 10, 2013 7:24 pm
I am getting to think I may prefer to start some sort of daemon that will see if the Zaurus connection is viable, and start or restart it if it is not. I keep accidentally knocking the zaurus out of the docking station and haveing to restart the connection manually at least a few times a day.

But I have not yet figured out what to have the daemon look for. More homework to do on that, but I want to know where in Arch in the /proc file system I can find a listing of usb devices and what drivers, if any, they are attached to? Crawling through logs makes less sense to me, there is a /proc/ file or node on my Zaurus that gives that information, along with a bunch of other device information, but I am not finding it on the Pi. lsusb -v does not mention drivers, that I could tell. And if the driver is active, lsmod does not tell me which device it is attached to, if any.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || This Pi owner is running Arch on 512MB Model B.
Posts: 1294
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by pepedog » Thu Jan 10, 2013 8:58 pm
As I undestand it, udevil comes with devmon
It monitors devices and you can run a script
I'm looking into udevil now as automount seems broken, at least on usb but sd card mounts ok (subsequent partitions)
Posts: 968
Joined: Fri Oct 07, 2011 9:55 am
by sdjf » Sun Jan 13, 2013 10:28 pm
udevil sounds good for monitoring SD cards, I have been unable to get my Pi to let me unmount an SD card that is long gone, it keeps saying it is being used by some process when I cannot find anything using it, with ps. Yes, I know to "umount" devices, but when my PDA got disconnected, the only way I could plug the keyboard back in was to remove the SD card without unmounting it.

another tool you might want to install that is pretty basic is lsof for seeing all files being accessed at any point. It does not show the card.

But will either of these monitor my zaurus when the connection gets severed accidentally? That is driving me nuts. I see kevent entries in the logs, when zaurus disconnects, but have no idea how to test for this and get the pi to restore the network. Sometimes I can get it to restore connection, sometimes the only way is to reflash the image, because it does not notice that the keyboard has moved to a different hub or usb port, at least that is what I think may be going on.

If I erased everything in /proc, would that reset everything when I rebooted? Tempted to do that when have a way to edit the file system, rather than have to reflash a couple times a day.

Would udevil or netmon notice the odd usb0 connection and restore it without me having to rescue it live with an unrecognized keyboard?
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || This Pi owner is running Arch on 512MB Model B.
Posts: 1294
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by pepedog » Sun Jan 13, 2013 11:57 pm
Posts: 968
Joined: Fri Oct 07, 2011 9:55 am
by sdjf » Mon Jan 14, 2013 12:52 am
Looks interesting, requires also installing ifplugd. A little concerned though, it may not support my usb network, only ethernet is mentioned as connection type.

So, there are no built in daemons in the basic Arch image that monitor connections and devices? I guess if you added everything everyone wanted, it would get huge with stuff not everyone needed.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || This Pi owner is running Arch on 512MB Model B.
Posts: 1294
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by sdjf » Mon Jan 14, 2013 2:12 am
Looks like netcfg will not do what I need. Says it uses ifplugd for wired connections.

And ifplugd is ONLY for ethernet and WLAN, per author:

http://0pointer.de/lennart/projects/ifplugd/
4. Q: Does it work with anything else than plain ethernet or wireless LAN?
A: Certainly not, since the MII and ETHTOOL ioctl()s and the wireless extension don't exist on other network device types.


Unless somebody modified it to include usbnet.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || This Pi owner is running Arch on 512MB Model B.
Posts: 1294
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by sdjf » Mon Jan 14, 2013 4:31 am
I think that plain udev may do what I want, found the following thread about how to run a script when a USB device is plugged in

http://ubuntuforums.org/archive/index.php/t-502864.html

I am going to try the following.

file: /etc/udev/rules.d/85-my_rule.rules

contents, one rule per line:

ACTION=="add", SYSFS{idVendor}=="04dd", RUN+="/boot/z.sh"
ACTION=="add", SYSFS{idVendor}=="04dd", SYSFS{idProduct}=="8004", RUN+="/root/c.sh"
ACTION=="add", SYSFS{idVendor}=="04dd", SYSFS{idProduct}=="9032", RUN+="/root/t.sh"

first line runs script when any zaurus is plugged in, lines 2 and 3 run additional unique scripts for each of the two different models I have....I hope.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || This Pi owner is running Arch on 512MB Model B.
Posts: 1294
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by sdjf » Wed Jan 16, 2013 4:20 am
Well, the udev rule did not run my script. Does udev watch for when things get unplugged and plugged back in again?

Very discouraging.

I wonder if maybe because my PDA only lost the connection for a few moments, that while the interface went down, whatever monitors for devices did not notice the PDA had gone away and come back because the monitoring is only every so many seconds or minutes? If that is what is happening, maybe I need to write a script that does a better job and checks the status more often.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || This Pi owner is running Arch on 512MB Model B.
Posts: 1294
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by pepedog » Wed Jan 16, 2013 10:48 am
I have been trying to look how udevil works with devmon, doesn't help there is no man page for devmon
devmon scans every 2 seconds, btw, it has to be enabled with systemctl enable devmon@root
wvdial uses something simple to reconnect, don't understand how it works
https://wiki.archlinux.org/index.php/Wv ... _Reconnect
Posts: 968
Joined: Fri Oct 07, 2011 9:55 am
by sdjf » Wed Jan 16, 2013 11:23 am
I decided not to use udevil as it clearly states (author's site) that it will only work for certain networking types not including mine. Am using the standard built in udev instead.

My earlier posts in this thread point to a thread elsewhere where people are getting udev rules (not udevil) to recognize usb devices when plugged in.

Another page I found about udev rules is following:

http://www.reactivated.net/writing_udev_rules.html

Also, I am not using wvdial, I got plain old ppp-on to work, logged in to ISP successfully but was unable to ping anybody. nameservers had not been added to resolv.conf so added them for next time, but will be a while. Pi will not let me back in with that rule not working and typing on keyboard not recognized.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || This Pi owner is running Arch on 512MB Model B.
Posts: 1294
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by pepedog » Wed Jan 16, 2013 1:34 pm
I wasn't pointing out wvdial as soloution, but for reconnect script
Posts: 968
Joined: Fri Oct 07, 2011 9:55 am
by sdjf » Thu Jan 17, 2013 1:48 pm
wvdial is only for pppd connections with a modem, so I think that will not work in this case.

I did get the udev rule working, syntax has changed. SYSFS has to be replaced with ATTR in udev rules.
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || This Pi owner is running Arch on 512MB Model B.
Posts: 1294
Joined: Fri Mar 16, 2012 5:20 am
Location: California