You are not logged in.

#1 2013-05-04 19:04:34

mkkot
Member
From: Poland
Registered: 2009-12-20
Posts: 196
Website

Systemd custom service pretends to work

Hello,

I wrote few months ago a hdparm service for systemd which looks like:

[root@linux mk]# cat /etc/systemd/system/hdparm.service 

[Unit]
Description=sdb drive spin-downs after 30 minutes

[Service]
Type=oneshot
RemainAfterExit=1
ExecStart=/sbin/hdparm -S 241 /dev/sdb

[Install]
WantedBy=multi-user.target

It stopped to work few weeks ago:

root@linux mk]# systemctl status hdparm.service 
hdparm.service - sdb drive spin-downs after 30 minutes
   Loaded: loaded (/etc/systemd/system/hdparm.service; enabled)
   Active: active (exited) since sob 2013-05-04 20:29:41 CEST; 21min ago
  Process: 239 ExecStart=/sbin/hdparm -S 241 /dev/sdb (code=exited, status=0/SUCCESS)

maj 04 20:29:41 linux hdparm[239]: /dev/sdb:
maj 04 20:29:41 linux hdparm[239]: setting standby to 241 (30 minutes)
maj 04 20:29:41 linux systemd[1]: Started sdb drive spin-downs after 30 minutes.
[root@linux mk]# journalctl -b -u hdparm
-- Logs begin at nie 2013-03-03 15:20:12 CET, end at sob 2013-05-04 20:55:56 CEST. --
maj 04 20:29:41 linux hdparm[239]: /dev/sdb:
maj 04 20:29:41 linux hdparm[239]: setting standby to 241 (30 minutes)
maj 04 20:29:41 linux systemd[1]: Started sdb drive spin-downs after 30 minutes.

Executing

/sbin/hdparm -S 241 /dev/sdb

manually works. What I mean by "it stopped to work"? Well, the disk isn't spun down.

I just tried manually if it executes hdparm. I changed the service file to hdparm -S 2, then systemctl --system daemon-reload and systemctl start hdparm.service -- works. Strange.

//edit -- on /dev/sdb I have only ONE partition which is NOT mounted while system starts. There is no way some process gets access to the filesystem.

Last edited by mkkot (2013-05-04 19:22:50)

Offline

#2 2013-05-04 19:39:55

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: Systemd custom service pretends to work

So is this not running at all, or is it not running on boot?  If it is not running on boot, it might be because the device is not yet available for the command to be run on.  I would instead use a udev rule to have to activate when the device has been found and setup.

Also, since you have multiple disks, using /dev/sdb is probably not the best idea.  It may be fairly consistently sdb on your machine, but this is not gauranteed.  Instead, you should use /dev/disk/by-*, as that is made to be consistent.

I had a Momentus XT that would make grinding/clicking noises when it spun down.  So I made a udev rule to have it never spin down.  I don't use this anymore, as I no longer have the disk in my machine, but the rule is apparently still there.  This is what it looks like:

% cat /etc/udev/rules.d/90-hdparm.rules
ACTION=="add", SUBSYSTEM=="block", ATTRS{model}=="ST95005620AS", RUN+="/sbin/hdparm -B 247 /dev/$kernel"

So to find tis information I had to learn hot to use udevadm.  The Arch wiki page for udev has some basics, but there is also a link there which is a great intro to writing basic udev rules.  It is a bit old, but the only thing that has changed is that instead of the command being udev, it has changed to udevadm.

Offline

#3 2013-05-04 19:55:34

mkkot
Member
From: Poland
Registered: 2009-12-20
Posts: 196
Website

Re: Systemd custom service pretends to work

Thanks for the reply. It runs at boot, that's how I have logs that it was executed properly. If the device wasn't detected, I'd have something like this:

[root@linux mk]# /sbin/hdparm -S 2 /dev/sdd
/dev/sdd: No such file or directory

or:

root@linux mk]# /sbin/hdparm -S 2 /dev/sdc

/dev/sdc:
 setting standby to 2 (10 seconds)
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

But it claims to work:

[root@linux mk]# journalctl -b -u hdparm
-- Logs begin at nie 2013-03-03 15:20:12 CET, end at sob 2013-05-04 20:55:56 CEST. --
maj 04 20:29:41 linux hdparm[239]: /dev/sdb:
maj 04 20:29:41 linux hdparm[239]: setting standby to 241 (30 minutes)

I have changed the command to be more precise and now it's ExecStart=/sbin/hdparm -S 241 /dev/disk/by-id/ata-SAMSUNG_SP2504C_S09QJ1GLB15632

I'll test if it produces any other output...

Last edited by mkkot (2013-05-04 19:56:26)

Offline

#4 2013-05-04 20:10:48

mkkot
Member
From: Poland
Registered: 2009-12-20
Posts: 196
Website

Re: Systemd custom service pretends to work

Just rebooted:

[root@linux mk]# journalctl -b -u hdparm
-- Logs begin at nie 2013-03-03 15:20:12 CET, end at sob 2013-05-04 22:07:36 CEST. --
maj 04 22:05:51 linux systemd[1]: Starting sdb drive spin-downs after 30 minutes...
maj 04 22:05:51 linux hdparm[240]: /dev/disk/by-id/ata-SAMSUNG_SP2504C_S09QJ1GLB15632:
maj 04 22:05:51 linux hdparm[240]: setting standby to 241 (30 minutes)
maj 04 22:05:52 linux systemd[1]: Started sdb drive spin-downs after 30 minutes.

Now I'm curious if it will put it in standby...

Offline

#5 2013-05-04 20:32:43

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: Systemd custom service pretends to work

mkkot wrote:

Now I'm curious if it will put it in standby...

That is the question now, isn't it? wink

Offline

#6 2013-05-04 20:39:21

mkkot
Member
From: Poland
Registered: 2009-12-20
Posts: 196
Website

Re: Systemd custom service pretends to work

And the answer is no, unfortunately. I'm really confused...

Offline

#7 2013-05-04 23:00:17

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: Systemd custom service pretends to work

Tryo the udev rule?

Offline

#8 2013-05-04 23:02:47

mkkot
Member
From: Poland
Registered: 2009-12-20
Posts: 196
Website

Re: Systemd custom service pretends to work

Yeah... too simple ;p But maybe it's the right way to follow.

Offline

#9 2013-05-04 23:07:10

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: Systemd custom service pretends to work

Trying to make it as hard as you can on yourself, eh?

In any case, I do think that the udev rule would in fact be the "correct way".

Offline

#10 2013-05-09 22:39:19

mkkot
Member
From: Poland
Registered: 2009-12-20
Posts: 196
Website

Re: Systemd custom service pretends to work

Doh, it doesn't work. How to debug that thing? I can't see it in journalctl.

Offline

#11 2013-05-10 01:19:06

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: Systemd custom service pretends to work

What is it you are actually trying now?  Are you using a service still, or a udev rule?

If it is a udev rule, post the output of:

$ udevadm info -a -p $(udevadm info -q path -n /dev/sdX)

Where X is the drive you are trying to apply the rule to (obviously).

Also, post your udev rule itself.  Maybe we can find where yu have gone wrong.

Offline

#12 2013-05-10 08:49:55

mkkot
Member
From: Poland
Registered: 2009-12-20
Posts: 196
Website

Re: Systemd custom service pretends to work

Sorry for not being precise, it was late when I wrote that post ;p Okay, here's what I did:
1. removed hdparm service from systemd
2. Added a udev rule like in your example:

[root@linux mk]# cat /etc/udev/rules.d/90-hdparm.rules
# /dev/sdb sleeps after 30 minutes
ACTION=="add", SUBSYSTEM=="block", ATTRS{model}=="S09QJ1GLB15632", RUN+="/sbin/hdparm -S 241 /dev/$kernel"

And the output is:

[mk@linux ~]$ udevadm info -q path -n /dev/disk/by-id/ata-SAMSUNG_SP2504C_S09QJ1GLB15632
/devices/pci0000:00/0000:00:08.1/ata3/host2/target2:0:0/2:0:0:0/block/sdb

Offline

#13 2013-05-10 13:10:04

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: Systemd custom service pretends to work

Hmmm.... I don't think you looked closely enough at the example command I put there.  What you pasted is using udevadm to get the path (after /sys) from a regular /dev/* path.  While this is a great thing, the output that is really needed is from the --attribute-walk command part.

Offline

#14 2013-05-10 21:05:00

mkkot
Member
From: Poland
Registered: 2009-12-20
Posts: 196
Website

Re: Systemd custom service pretends to work

Okay, now I can see it's actually wrong. However I have no idea how to make it right:

[mk@linux ~]$ udevadm info -a -p $(udevadm info -q path -n /dev/disk/by-id/ata-SAMSUNG_SP2504C_S09QJ1GLB15632)

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:08.1/ata3/host2/target2:0:0/2:0:0:0/block/sdb':
    KERNEL=="sdb"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{ro}=="0"
    ATTR{size}=="488397168"
    ATTR{stat}=="     360     1138     2858      216        0        0        0        0        0      216      216"
    ATTR{range}=="16"
    ATTR{discard_alignment}=="0"
    ATTR{events}==""
    ATTR{ext_range}=="256"
    ATTR{events_poll_msecs}=="-1"
    ATTR{alignment_offset}=="0"
    ATTR{inflight}=="       0        0"
    ATTR{removable}=="0"
    ATTR{capability}=="50"
    ATTR{events_async}==""

  looking at parent device '/devices/pci0000:00/0000:00:08.1/ata3/host2/target2:0:0/2:0:0:0':
    KERNELS=="2:0:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS=="sd"
    ATTRS{rev}=="VT10"
    ATTRS{type}=="0"
    ATTRS{scsi_level}=="6"
    ATTRS{model}=="SAMSUNG SP2504C "
    ATTRS{state}=="running"
    ATTRS{queue_type}=="none"
    ATTRS{iodone_cnt}=="0x1c3"
    ATTRS{iorequest_cnt}=="0x1c3"
    ATTRS{timeout}=="30"
    ATTRS{evt_media_change}=="0"
    ATTRS{ioerr_cnt}=="0x18"
    ATTRS{queue_depth}=="1"
    ATTRS{vendor}=="ATA     "
    ATTRS{device_blocked}=="0"
    ATTRS{iocounterbits}=="32"

  looking at parent device '/devices/pci0000:00/0000:00:08.1/ata3/host2/target2:0:0':
    KERNELS=="target2:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:08.1/ata3/host2':
    KERNELS=="host2"
    SUBSYSTEMS=="scsi"
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:08.1/ata3':
    KERNELS=="ata3"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:08.1':
    KERNELS=="0000:00:08.1"
    SUBSYSTEMS=="pci"
    DRIVERS=="sata_nv"
    ATTRS{irq}=="20"
    ATTRS{subsystem_vendor}=="0x1458"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x010185"
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{local_cpus}=="00000000,00000003"
    ATTRS{device}=="0x03f6"
    ATTRS{msi_bus}==""
    ATTRS{local_cpulist}=="0-1"
    ATTRS{vendor}=="0x10de"
    ATTRS{subsystem_device}=="0xb002"
    ATTRS{numa_node}=="0"
    ATTRS{d3cold_allowed}=="1"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

I can't use model string to specify the disk because I have 2 physical drives called SAMSUNG SP2504C.

Offline

#15 2013-05-11 00:45:32

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: Systemd custom service pretends to work

Oh, you have two disks of the same model?  Then I think you need to give output specifically for the one you wish to write a udev rule for. 

Did you read through the Arch wiki page on udev?  There is a link to writing udev rules there. The linked page is short, and very straight forward, as it only covers the most basic of use cases (which is enough for what you want to do here).

In short, you need to give it enough info to be able to identify only that disk.  But you also may use anything from the top level, that is the section with ATTR and not ATTRS, and you may use stuff below it.  But if you use stuff below it, you may only use things from teh same section.  So if this is indeed the disk you actually want to use, you might do something like this:

ACTION=="add", SUBSYSTEM=="block", KERNELS=="2:0:0:0", RUN+="/sbin/hdparm -S 241 /dev/$kernel"

So you see that I used SUBSYSTEM=="block" there.  If you had wanted to use a subsystem below that of some kind.  You would have had to have used the SUBSYSTEM=="scsi" because it  would be in the same section as KERNELS="2:0:0:0".  So I think that should actually work.  You might want to check to make sure, but I am fairly certain that other disks will result in a different KERNELS=="x:0:0:0".

Offline

#16 2013-05-12 21:37:48

mkkot
Member
From: Poland
Registered: 2009-12-20
Posts: 196
Website

Re: Systemd custom service pretends to work

I was reading the page you recommended and few others... darn, it's not that easy. I used the rule you provided in your post and it seems to work (the line before the last one):

[root@linux mk]# udevadm test /sys/block/sdb/
calling: test
version 203
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

=== trie on-disk ===
tool version:          203
file size:         5632867 bytes
header size             80 bytes
strings            1260755 bytes
nodes              4372032 bytes
load module index
Skipping overridden file: /usr/lib/udev/rules.d/80-net-name-slot.rules.
read rules file: /usr/lib/udev/rules.d/10-dm.rules
read rules file: /usr/lib/udev/rules.d/11-dm-lvm.rules
read rules file: /usr/lib/udev/rules.d/13-dm-disk.rules
read rules file: /usr/lib/udev/rules.d/40-gphoto.rules
read rules file: /usr/lib/udev/rules.d/40-hpet-permissions.rules
read rules file: /usr/lib/udev/rules.d/40-hplip.rules
read rules file: /usr/lib/udev/rules.d/40-usb-media-players.rules
read rules file: /usr/lib/udev/rules.d/42-usb-hid-pm.rules
read rules file: /usr/lib/udev/rules.d/50-firmware.rules
read rules file: /usr/lib/udev/rules.d/50-udev-default.rules
read rules file: /usr/lib/udev/rules.d/53-sane.rules
read rules file: /usr/lib/udev/rules.d/56-hpmud_add_printer.rules
read rules file: /usr/lib/udev/rules.d/56-hpmud_support.rules
read rules file: /usr/lib/udev/rules.d/60-cdrom_id.rules
read rules file: /usr/lib/udev/rules.d/60-ffado.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-alsa.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-input.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-serial.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-storage-tape.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-storage.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-v4l.rules
read rules file: /usr/lib/udev/rules.d/61-accelerometer.rules
read rules file: /usr/lib/udev/rules.d/64-btrfs.rules
read rules file: /usr/lib/udev/rules.d/69-cd-sensors.rules
IMPORT found builtin 'usb_id --export %p', replacing /usr/lib/udev/rules.d/69-cd-sensors.rules:89
read rules file: /usr/lib/udev/rules.d/69-dm-lvm-metad.rules
read rules file: /usr/lib/udev/rules.d/69-libmtp.rules
read rules file: /usr/lib/udev/rules.d/70-infrared.rules
read rules file: /usr/lib/udev/rules.d/70-power-switch.rules
read rules file: /usr/lib/udev/rules.d/70-uaccess.rules
read rules file: /usr/lib/udev/rules.d/70-udev-acl.rules
read rules file: /usr/lib/udev/rules.d/71-seat.rules
read rules file: /usr/lib/udev/rules.d/73-seat-late.rules
read rules file: /usr/lib/udev/rules.d/75-net-description.rules
read rules file: /usr/lib/udev/rules.d/75-probe_mtd.rules
read rules file: /usr/lib/udev/rules.d/75-tty-description.rules
read rules file: /usr/lib/udev/rules.d/78-sound-card.rules
read rules file: /usr/lib/udev/rules.d/80-drivers.rules
read rules file: /etc/udev/rules.d/80-net-name-slot.rules
read rules file: /usr/lib/udev/rules.d/80-udisks.rules
read rules file: /usr/lib/udev/rules.d/80-udisks2.rules
read rules file: /usr/lib/udev/rules.d/85-usbmuxd.rules
read rules file: /usr/lib/udev/rules.d/86-hpmud_plugin.rules
read rules file: /usr/lib/udev/rules.d/90-alsa-restore.rules
read rules file: /etc/udev/rules.d/90-hdparm.rules
read rules file: /usr/lib/udev/rules.d/90-pulseaudio.rules
read rules file: /usr/lib/udev/rules.d/95-cd-devices.rules
read rules file: /usr/lib/udev/rules.d/95-dm-notify.rules
read rules file: /usr/lib/udev/rules.d/95-keyboard-force-release.rules
read rules file: /usr/lib/udev/rules.d/95-keymap.rules
read rules file: /usr/lib/udev/rules.d/95-udev-late.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-dell.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-fujitsu.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-gateway.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-ibm.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-lenovo.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-toshiba.rules
read rules file: /usr/lib/udev/rules.d/95-upower-csr.rules
read rules file: /usr/lib/udev/rules.d/95-upower-hid.rules
read rules file: /usr/lib/udev/rules.d/95-upower-wup.rules
read rules file: /etc/udev/rules.d/99-gpusb.rules
read rules file: /usr/lib/udev/rules.d/99-systemd.rules
rules contain 393216 bytes tokens (32768 * 12 bytes), 40284 bytes strings
28908 strings (240888 bytes), 25286 de-duplicated (204227 bytes), 3623 trie nodes used
GROUP 6 /usr/lib/udev/rules.d/50-udev-default.rules:50
IMPORT 'ata_id --export /dev/sdb' /usr/lib/udev/rules.d/60-persistent-storage.rules:30
starting 'ata_id --export /dev/sdb'
'ata_id --export /dev/sdb' [11055] exit with return code 0
LINK 'disk/by-id/ata-SAMSUNG_SP2504C_S09QJ1GLB15632' /usr/lib/udev/rules.d/60-persistent-storage.rules:42
IMPORT builtin 'path_id' /usr/lib/udev/rules.d/60-persistent-storage.rules:55
IMPORT builtin 'path_id' returned non-zero
IMPORT builtin 'blkid' /usr/lib/udev/rules.d/60-persistent-storage.rules:70
probe /dev/sdb raid offset=0
LINK 'disk/by-id/wwn-0x50000f001bb15632' /usr/lib/udev/rules.d/60-persistent-storage.rules:80
IMPORT 'udisks-part-id /dev/sdb' /usr/lib/udev/rules.d/80-udisks.rules:84
starting 'udisks-part-id /dev/sdb'
'udisks-part-id /dev/sdb' [11056] exit with return code 0
IMPORT 'udisks-probe-ata-smart /dev/sdb' /usr/lib/udev/rules.d/80-udisks.rules:111
starting 'udisks-probe-ata-smart /dev/sdb'
'udisks-probe-ata-smart /dev/sdb' [11057] exit with return code 0
RUN '/sbin/hdparm -S 241 /dev/$kernel' /etc/udev/rules.d/90-hdparm.rules:2
handling device node '/dev/sdb', devnum=b8:16, mode=0660, uid=0, gid=6
preserve permissions /dev/sdb, 060660, uid=0, gid=6
preserve already existing symlink '/dev/block/8:16' to '../sdb'
found 'b8:16' claiming '/run/udev/links/\x2fdisk\x2fby-id\x2fata-SAMSUNG_SP2504C_S09QJ1GLB15632'
creating link '/dev/disk/by-id/ata-SAMSUNG_SP2504C_S09QJ1GLB15632' to '/dev/sdb'
preserve already existing symlink '/dev/disk/by-id/ata-SAMSUNG_SP2504C_S09QJ1GLB15632' to '../../sdb'
found 'b8:16' claiming '/run/udev/links/\x2fdisk\x2fby-id\x2fwwn-0x50000f001bb15632'
creating link '/dev/disk/by-id/wwn-0x50000f001bb15632' to '/dev/sdb'
preserve already existing symlink '/dev/disk/by-id/wwn-0x50000f001bb15632' to '../../sdb'
ACTION=add
DEVLINKS=/dev/disk/by-id/ata-SAMSUNG_SP2504C_S09QJ1GLB15632 /dev/disk/by-id/wwn-0x50000f001bb15632
DEVNAME=/dev/sdb
DEVPATH=/devices/pci0000:00/0000:00:08.1/ata3/host2/target2:0:0/2:0:0:0/block/sdb
DEVTYPE=disk
ID_ATA=1
ID_ATA_DOWNLOAD_MICROCODE=1
ID_ATA_FEATURE_SET_AAM=1
ID_ATA_FEATURE_SET_AAM_CURRENT_VALUE=0
ID_ATA_FEATURE_SET_AAM_ENABLED=0
ID_ATA_FEATURE_SET_AAM_VENDOR_RECOMMENDED_VALUE=254
ID_ATA_FEATURE_SET_HPA=1
ID_ATA_FEATURE_SET_HPA_ENABLED=1
ID_ATA_FEATURE_SET_PM=1
ID_ATA_FEATURE_SET_PM_ENABLED=1
ID_ATA_FEATURE_SET_SECURITY=1
ID_ATA_FEATURE_SET_SECURITY_ENABLED=0
ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN=88
ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=88
ID_ATA_FEATURE_SET_SMART=1
ID_ATA_FEATURE_SET_SMART_ENABLED=1
ID_ATA_SATA=1
ID_ATA_SATA_SIGNAL_RATE_GEN1=1
ID_ATA_SATA_SIGNAL_RATE_GEN2=1
ID_ATA_WRITE_CACHE=1
ID_ATA_WRITE_CACHE_ENABLED=1
ID_BUS=ata
ID_MODEL=SAMSUNG_SP2504C
ID_MODEL_ENC=SAMSUNG\x20SP2504C\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
ID_PART_TABLE_TYPE=dos
ID_REVISION=VT100-50
ID_SERIAL=SAMSUNG_SP2504C_S09QJ1GLB15632
ID_SERIAL_SHORT=S09QJ1GLB15632
ID_TYPE=disk
ID_WWN=0x50000f001bb15632
ID_WWN_WITH_EXTENSION=0x50000f001bb15632
MAJOR=8
MINOR=16
SUBSYSTEM=block
TAGS=:systemd:
UDISKS_ATA_SMART_IS_AVAILABLE=1
UDISKS_PARTITION_TABLE=1
UDISKS_PARTITION_TABLE_COUNT=2
UDISKS_PARTITION_TABLE_SCHEME=mbr
UDISKS_PRESENTATION_NOPOLICY=0
USEC_INITIALIZED=49937
run: '/sbin/hdparm -S 241 /dev/sdb'
unload module index

But it doesn't hmm How can I check what $kernel actually stands for? Maybe it'd be better to change it to something else?

Offline

#17 2013-05-13 00:02:40

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: Systemd custom service pretends to work

It works... but it doesn't?  You've got to be a bit more clear than that.  From the output there, it seems to be running hdparm on sdb... is that not what you want? 

/dev/$kernel is whatever the kernel name is for that particular hardware path (2:0:0:0).  So you need to determine what that is.  You can probably go searching through /sys to find it, or just use hdparm to find that info as well. 

I really didn't fund that document about writing udev rules all that complicated.  It covers the most basic forms, but I guess I was also writing and trying them as I went along.  So I was really learning by doing.  I think that by me simply giving you these rules, I am actually hindering your ability to understand for yourself.  So sorry about that.

If you have something more specific about what your issue might be, I'll check back on this thread.  Good luck sir!

Offline

#18 2013-05-13 08:57:05

mkkot
Member
From: Poland
Registered: 2009-12-20
Posts: 196
Website

Re: Systemd custom service pretends to work

Yeah, thanks for understanding. We have such saying in Poland: it's better to give a fishing-rod than a fish wink

Well, as you can see, from the output udev is performing /sbin/hdparm -S 241 /dev/sdb which is exactly what I want. However, the disk is not spun down after half an hour. If I run that command manually from console, I get the result I wanted.

Anyway, I was browsing journalctl for any details of this problem (haven't found any) and I think we could have wrongly named KERNELS path. Please look on that:

[root@linux mk]# journalctl -b |grep 2:0:0:0
maj 13 10:33:13 linux kernel: scsi 2:0:0:0: Direct-Access     ATA      SAMSUNG SP2504C  VT10 PQ: 0 ANSI: 5
maj 13 10:33:13 linux kernel: sd 2:0:0:0: [sda] 488395055 512-byte logical blocks: (250 GB/232 GiB)
maj 13 10:33:13 linux kernel: sd 2:0:0:0: [sda] Write Protect is off
maj 13 10:33:13 linux kernel: sd 2:0:0:0: [sda] Mode Sense: 00 3a 00 00
maj 13 10:33:13 linux kernel: sd 2:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
maj 13 10:33:13 linux kernel: sd 2:0:0:0: [sda] Attached SCSI disk
maj 13 10:33:15 linux kernel: sd 2:0:0:0: Attached scsi generic sg1 type 0
maj 13 10:33:25 linux udisks-daemon[300]: **** ADDING /sys/devices/pci0000:00/0000:00:08.0/ata3/host2/target2:0:0/2:0:0:0/block/sda
maj 13 10:33:25 linux udisks-daemon[300]: **** UPDATING /sys/devices/pci0000:00/0000:00:08.0/ata3/host2/target2:0:0/2:0:0:0/block/sda
maj 13 10:33:25 linux udisks-daemon[300]: **** ADDED /sys/devices/pci0000:00/0000:00:08.0/ata3/host2/target2:0:0/2:0:0:0/block/sda
maj 13 10:33:25 linux udisks-daemon[300]: **** ADDING /sys/devices/pci0000:00/0000:00:08.0/ata3/host2/target2:0:0/2:0:0:0/block/sda/sda1
...

And so on. It's sda across the whole output. And sdb?

[root@linux mk]# journalctl -b |grep sdb
maj 13 10:33:13 linux kernel: sd 4:0:0:0: [sdb] 488397168 512-byte logical blocks: (250 GB/232 GiB)
maj 13 10:33:13 linux kernel: sd 4:0:0:0: [sdb] Write Protect is off
maj 13 10:33:13 linux kernel: sd 4:0:0:0: [sdb] Mode Sense: 00 3a 00 00
maj 13 10:33:13 linux kernel: sd 4:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
maj 13 10:33:13 linux kernel:  sdb: sdb1 < sdb5 >
maj 13 10:33:13 linux kernel: sd 4:0:0:0: [sdb] Attached SCSI disk
maj 13 10:33:24 linux smartd[245]: Device: /dev/sdb, type changed from 'scsi' to 'sat'
maj 13 10:33:24 linux smartd[245]: Device: /dev/sdb [SAT], opened
maj 13 10:33:24 linux smartd[245]: Device: /dev/sdb [SAT], SAMSUNG SP2504C, S/N:S09QJ1GLB15632, FW:VT100-50, 250 GB
maj 13 10:33:24 linux smartd[245]: Device: /dev/sdb [SAT], found in smartd database: SAMSUNG SpinPoint P120
maj 13 10:33:24 linux smartd[245]: Device: /dev/sdb [SAT], WARNING: May need -F samsung3 enabled; see manual for details.
maj 13 10:33:25 linux smartd[245]: Device: /dev/sdb [SAT], is SMART capable. Adding to "monitor" list.
maj 13 10:33:25 linux udisks-daemon[300]: **** ADDING /sys/devices/pci0000:00/0000:00:08.1/ata5/host4/target4:0:0/4:0:0:0/block/sdb
maj 13 10:33:25 linux udisks-daemon[300]: **** UPDATING /sys/devices/pci0000:00/0000:00:08.1/ata5/host4/target4:0:0/4:0:0:0/block/sdb
maj 13 10:33:25 linux udisks-daemon[300]: helper(pid   320): launched job udisks-helper-ata-smart-collect on /dev/sdb
maj 13 10:33:25 linux udisks-daemon[300]: **** ADDED /sys/devices/pci0000:00/0000:00:08.1/ata5/host4/target4:0:0/4:0:0:0/block/sdb
maj 13 10:33:25 linux udisks-daemon[300]: **** ADDING /sys/devices/pci0000:00/0000:00:08.1/ata5/host4/target4:0:0/4:0:0:0/block/sdb/sdb1
maj 13 10:33:25 linux udisks-daemon[300]: **** UPDATING /sys/devices/pci0000:00/0000:00:08.1/ata5/host4/target4:0:0/4:0:0:0/block/sdb/sdb1
...

I'm going to change the path, we'll see if it helps:

[root@linux mk]# cat /etc/udev/rules.d/90-hdparm.rules
# /dev/sdb sleeps after 30 minutes
ACTION=="add", SUBSYSTEM=="block", KERNELS=="4:0:0:0", RUN+="/sbin/hdparm -S 241 /dev/$kernel"

Last edited by mkkot (2013-05-13 08:59:50)

Offline

#19 2013-05-19 22:15:47

mkkot
Member
From: Poland
Registered: 2009-12-20
Posts: 196
Website

Re: Systemd custom service pretends to work

Nope, it doesn't work. But still, with the new setting I can see in udevadm test /sys/block/sdb/:

run: '/sbin/hdparm -S 241 /dev/sdb'

I think I don't have enough will to fight it anymore. Maybe it's just broken...

Offline

#20 2013-05-19 22:21:17

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: Systemd custom service pretends to work

Yeah, honestly, at this point I am fresh out of ideas.  Sorry man... sad

Offline

#21 2013-05-20 08:44:59

mkkot
Member
From: Poland
Registered: 2009-12-20
Posts: 196
Website

Re: Systemd custom service pretends to work

Anyway, I'm grateful for your help smile I'll probably make a bugreport from this to Lennard Poettering when I have too much time ;p

Offline

#22 2013-05-20 16:40:22

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: Systemd custom service pretends to work

You could always just ask on the systemd mailing list.  They are udev these days, so I am sure you could probably get some help there.  It is a generally very welcoming list, though Lennart is usually so busy with the mass amounts of email directed towards him that it takes him a few days to respond.  But there are many other very knowledgeable people who participate in that list, including Tom Gunderson, Dave Reisner, and Allan McRae of Arch Linux.

Oh and there is always IRC.  You can probably get some near instant support there.  #archlinux is probably the most active support IRC channel I have ever seen.

Offline

Board footer

Powered by FluxBB