Pogoplug EO2: Change LED color - only as root?

This forum is for Marvell Kirkwood devices such as the GoFlex Home/Net, PogoPlug v1/v2, SheevaPlug, and ZyXEL devices.

Pogoplug EO2: Change LED color - only as root?

Postby gryphraff » Tue Feb 18, 2014 9:00 pm

I have an application where I want to change the front panel's LED color based on an event - in this case, a weather alert for my area.

I want to run the program as a non-root user, both because it's exposed to the outside world, and I don't want the emails it generates coming from root@mydomain. I'm able to get everything to work, but I can't get the LED to change as any user other than root. It always tells me that I can't write to that directory.

I've tried adding my user to the sudoers file, giving my user RW capability to the specific directory the LEDs are in, and a couple of other things that I can't remember. I can elevate to root, but that seems to have it's own set of problems. Is there any way that I can control this without being root? I feel like I'm missing something here.
gryphraff
 
Posts: 3
Joined: Tue Feb 18, 2014 6:52 pm

Re: Pogoplug EO2: Change LED color - only as root?

Postby hydro » Wed Feb 19, 2014 10:00 am

Add this to the sudoers file (using e.g. VISUAL=nano visudo)
Code: Select all
user ALL=(root) NOPASSWD: /usr/bin/tee /sys/class/leds/status\:green\:health/trigger
user ALL=(root) NOPASSWD: /usr/bin/tee /sys/class/leds/status\:orange\:fault/trigger

Now user will be able to change LEDs as follows
Code: Select all
$ echo heartbeat | sudo tee /sys/class/leds/status\:green\:health/trigger


Or use a little program I wrote a while ago:
Code: Select all
$ wget http://linux.bplaced.net/led.c
$ gcc -o led led.c

Code: Select all
# cp led /usr/local/bin/led_green
# ln /usr/local/bin/led_green /usr/local/bin/led_orange

Code: Select all
user ALL=(root) NOPASSWD: /usr/local/bin/led_green, /usr/local/bin/led_orange

Code: Select all
$ led_green
none nand-disk timer ide-disk [heartbeat] default-on rc-feedback
$ sudo led_green default-on
VDR on DockStar / Pogoplug E02: http://linux.bplaced.net/
hydro
 
Posts: 210
Joined: Wed Jun 15, 2011 2:03 pm
Location: Germany

Re: Pogoplug EO2: Change LED color - only as root?

Postby gryphraff » Thu Feb 20, 2014 2:33 am

Thanks. That allows me to change the LEDs, but still asks for a SUDO password - I assumed the NOPASSWD: would take care of that.

Running that command in a cronjob gives me:

Code: Select all
sudo: no tty present and no askpass program specified


which makes sense, since it's asking me for a password and it can't get one due to lack of console or other piped in data. I'm going to play around with this when I have a bit more time. I may have something broken in my install, and I need to read up on sudo permissions.
gryphraff
 
Posts: 3
Joined: Tue Feb 18, 2014 6:52 pm

Re: Pogoplug EO2: Change LED color - only as root?

Postby hydro » Thu Feb 20, 2014 4:29 pm

A successive entry may overwrite your rule, e.g. if your user is in the group wheel and you uncommented the corresponding line
Code: Select all
user ALL=(root) NOPASSWD: /usr/bin/tee /sys/class/leds/status\:green\:health/trigger
user ALL=(root) NOPASSWD: /usr/bin/tee /sys/class/leds/status\:orange\:fault/trigger

## Uncomment to allow members of group wheel to execute any command
%wheel ALL=(ALL) ALL

then you will be prompted for a password, because the last entry includes the tee commands and has a higher priority.
VDR on DockStar / Pogoplug E02: http://linux.bplaced.net/
hydro
 
Posts: 210
Joined: Wed Jun 15, 2011 2:03 pm
Location: Germany

Re: Pogoplug EO2: Change LED color - only as root?

Postby gryphraff » Fri Feb 21, 2014 12:27 pm

I don't remember seeing anything else in the sudoers file, other than what's put there by the default install. I'll go over it again tonight to make sure.

I've done a lot of poking at this install, and my chosen flash drive is getting very slow, so I may do a re-install beforehand on a better drive.
gryphraff
 
Posts: 3
Joined: Tue Feb 18, 2014 6:52 pm


Return to Marvell Kirkwood

Who is online

Users browsing this forum: No registered users and 2 guests