Re: Help needed with systemd script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Dec 14, 2013 at 3:00 PM, Mattia Verga <mattia.verga@xxxxxxxxxx> wrote:
> Il 14/12/2013 12:55, Dridi Boukelmoune ha scritto:
>
> Hi,
>
> On Sat, Dec 14, 2013 at 12:44 PM, Mattia Verga <mattia.verga@xxxxxxxxxx>
> wrote:
>
> Hello,
> I'm trying to give a user access rights to X with xhost command.
> I've created a script named '/usr/bin/boincxhost' (chmod 555) like this:
>
> #!/bin/sh
> xhost +SI:localuser:boinc &> /dev/null
> exit 0
>
> "exit 0" will hide a non-zero exit status of the previous command.
>
> In this case I'm not sure what's happening, but if you're running the
> command in background, and don't wait for it to complete, you may be
> facing a race condition.
>
>
> Ok, I tried to edit the boincxhost script in this way:
>
> #!/bin/sh
> xhost +SI:localuser:boinc
> sleep 1

This time it's the sleep command that will override the xhost exit
status. Since you're running xhost in foreground, you shoudn't need to
sleep at all.

In general, if you have several commands in a script, but you want it
to abort as soon as one command fail, you can:
- run it with sh -e
- add set -e in your script

This is a one-command script, so you can simply run xhost, and the
shell exit status should be xhost's exit status. Btw, do you really
need a script ? Can't systemd handle something like:
ExecStartPre=/usr/bin/xhost +SI:localuser:boinc

> Now if I run the script from console I get:
> $ /usr/bin/boincxhost
> localuser:boinc being added to access control list
>
> $ xhost
> access control enabled, only authorized clients can connect
> SI:localuser:boinc
> SI:localuser:marvin
>
> But if I run it within systemd unit the service is started, but xhost
> command "silently" fails:
> # systemctl start boinc-client.service
> # systemctl status boinc-client.service
> boinc-client.service - Berkeley Open Infrastructure Network Computing Client
>    Loaded: loaded (/usr/lib/systemd/system/boinc-client.service; disabled)
>    Active: active (running) since sab 2013-12-14 14:52:25 CET; 4s ago
>   Process: 2843 ExecStopPost=/bin/rm -f /var/lib/boinc/lockfile
> (code=exited, status=0/SUCCESS)
>   Process: 2947 ExecStartPre=/usr/bin/boincxhost (code=exited,
> status=0/SUCCESS)
>   Process: 2944 ExecStartPre=/usr/bin/chown boinc:boinc /var/log/boinc.log
> /var/log/boincerr.log (code=exited, status=0/SUCCESS)
>   Process: 2941 ExecStartPre=/usr/bin/touch /var/log/boinc.log
> /var/log/boincerr.log (code=exited, status=0/SUCCESS)
>   Process: 2938 ExecStartPre=/bin/sleep 1 (code=exited, status=0/SUCCESS)
>  Main PID: 2952 (boinc)
>    CGroup: name=systemd:/system/boinc-client.service
>            ├─2952 /bin/bash /usr/bin/boinc --dir /var/lib/boinc
>            └─2953 /usr/bin/boinc_client --allow_multiple_clients --dir
> /var/l...
>
> dic 14 14:52:23 deneb systemd[1]: Starting Berkeley Open Infrastructure
> Net.....
> dic 14 14:52:24 deneb boincxhost[2947]: xhost:  unable to open display ""
> dic 14 14:52:25 deneb systemd[1]: Started Berkeley Open Infrastructure
> Netw...t.
>
> # xhost
> access control enabled, only authorized clients can connect
> SI:localuser:marvin
>
>
>
> --
> devel mailing list
> devel@xxxxxxxxxxxxxxxxxxxxxxx
> https://admin.fedoraproject.org/mailman/listinfo/devel
> Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
-- 
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxxx
https://admin.fedoraproject.org/mailman/listinfo/devel
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]
  Powered by Linux