1

I am trying to run an i3 command using inotify. In my case, inotify is started using systemctl.

systemctl script:

[Unit]
Description=Inode event watcher

[Service]
User=root
Type=forking
ExecStart=/usr/local/services/inotify/start.sh

[Install]
WantedBy=default.target

/usr/local/services/inotify/start.sh:

I3_CURRENT_WORKSPACE='/etc/i3/script/swiping-workspace/current'
I3_UPDATE_WORKSPACE="/etc/i3/script/swiping-workspace/update.sh"
inotify $I3_WORKSPACE_TRIGGER $I3_WORKSPACE_UPDATE &

Note: my goal here is to execute update.sh when the current file is changed on disk.

/etc/i3/script/swiping-workspace/update.sh:

sudo -u $user i3 workspace $(cat $I3_CURRENT_WORKSPACE)

where $user is the user in which i3 has been installed. I am running this command as root. I also tried these switches, no avail: SCREEN=':0' -E -H

The issue:

When an inotify event is triggered, an error occurs. Here is the log message I get (using journalctl):

<date> start.sh[1427]: /etc/i3/script/swiping-workspace/ MODIFY current
<date> sudo[6698]:     root : TTY=unknown ; PWD=/ ; USER=$user ; COMMAND=/usr/bin/i3 workspace "6"
<date> sudo[6698]: pam_unix(sudo:session): session opened for user $user by (uid=0)
<date> start.sh[1427]: <date> - Additional arguments passed. Sending them as a command to i3.
<date> start.sh[1427]: <date> - ERROR: Could not get i3 IPC socket path
<date> sudo[6698]: pam_unix(sudo:session): session closed for user $user

I don't understand why i3 fails to receive the command systemctl sends it.

The whole setup actually works if I start the inotify command myself (in a unique terminal) instead of using systemctl.

Anybody having a clue?

ljleb
  • 182
  • 1
  • 14
  • 1. Run the script as your own user 2. Ensure you set the DISPLAY variable correctly – Score_Under Feb 28 '19 at 16:50
  • See edited post. I tried to set `$SCREEN` with sudo's `-E` switch, and also I tried the `-H` switch, no avail. – ljleb Feb 28 '19 at 17:33
  • 2
    The correct variable is `DISPLAY`, not `$SCREEN`. You may also need `XAUTHORITY`. Bear in mind that sudo may have policies disallowing non-whitelisted environment variables. – Score_Under Mar 01 '19 at 12:05
  • Your script also still has `User=root` in the service file, and is using the `i3` command when it should use the `i3-msg` command. – Score_Under Mar 01 '19 at 12:08

0 Answers0