Hi 
Seems I still need some help from the community to achieve this custom autorun feature !
Here is what I achieved so far :
[ul]
[li]I built a custom TCP server binary that is started on XFCE startup that listens for requests [/li][li]The udev rule detects a change on the optical disc drive [/li][li]The systemd service is triggered from udev and runs a shell script that runs several commands :[/li][LIST]
[li]create each directory that would not already exist in the path /run/media/jean/Autoplay [/li][li]mount the disc into this /run/media/jean/Autoplay directory [/li][li]run a custom TCP client binary that sends a request to the server [/li][/ul]
[li]Then, the server runs a shell script that calls /lib64/ld-linux-x86-64.so.2 to run the binary /run/media/jean/Autoplay/autoplay-game.bin [/li][/LIST]
So, once I logged in and the XFCE session is ready, I can put my test disc in the drive and, after a few seconds (well, maybe more than few, it’s an optical drive after all), the game is started. Basically I mean that a window opens, and it’s a SFML sample that runs in it.
I’m pretty satisfied with this pipeline, but I still have one problem.
The fact is that this works every time, except the first time I put the disc in the drive.
Once logged in XFCE, inserting the disc does nothing. Ejecting and inserting it again, then, works fine and the whole process is ran. Every time I try it, it’s okay. If I reboot, then the very first attempt does nothing again.
So, I think I have a problem with the udev rule, somewhat not triggering the very first time a change is detected on the optical drive.
Once I have logged in XFCE after a fresh start or reboot, I can confirm my server is already listening, running
netstat -lt
and seeing the entry
tcp 0 0 *:15892 *:* LISTEN
for my binary. I tried to run my tests by manually running my server from a XFCE terminal instead of asking XFCE to run it on startup, with no difference.
If i run
systemctl status drive-change.service
, I get :
drive-change.service - AUTODVD Service
Loaded: loaded (/etc/systemd/system/drive-change.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Then, inserting the disc in the drive, waiting for it to stop spinning, I can tell that the game did not run, neither the disc was mounter or the directory created. And, in fact, the service itself was not triggered. If i run
systemctl status drive-change.service
again, I get the same exact output.
Ejecting, and inserting it again, then does a difference. The directory now exists, the disc is mounted (done by my script, as I configured XFCE to not mount the drive on insertion), and the game is started.
Doing yet another call to
systemctl status drive-change.service
gives this output :
drive-change.service - AUTODVD Service
Loaded: loaded (/etc/systemd/system/drive-change.service; disabled; vendor preset: disabled)
Active: inactive (dead) since mer. 2018-02-14 19:41:00 CET; 1min 23s ago
Process: 3083 ExecStart=/home/jean/Documents/Developpement/Shell/start-autodvd-cli.sh (code=exited, status=0/SUCCESS)
Main PID: 3083 (code=exited, status=0/SUCCESS)
févr. 14 19:41:00 cerbere.suse systemd[1]: Starting AUTODVD Service...
févr. 14 19:41:00 cerbere.suse start-autodvd-cli.sh[3083]: mount: /dev/sr0 is write-protected, mounting read-only
févr. 14 19:41:00 cerbere.suse start-autodvd-cli.sh[3083]: Server sent back : Acknowledge
févr. 14 19:41:00 cerbere.suse systemd[1]: Started AUTODVD Service.
So, I think this is related to the udev rule, but I can’t figure out why it would not trigger my service the very first time a disc is inserted after the system startup. :
Any ides on this issue ?
Here is my udev rule,
/etc/udev/rules.d/autodvd.rules
:
SUBSYSTEM=="block", ENV{ID_CDROM}=="?*", ACTION=="change", TAG+="systemd", ENV{SYSTEMD_WANTS}="drive-change.service"
And here is the service,
/etc/systemd/system/drive-change.service
, which has been modified a little :
[Unit]
Description=AUTODVD Service
[Service]
Type=oneshot
ExecStart=/home/jean/Documents/Developpement/Shell/start-autodvd-cli.sh
StandardOutput=journal
[Install]
WantedBy=dev-dvd.device
Any help will be much appreciated ! :shame:
Thanks by advance