Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved]Need help porting /etc/local.d script to systemd
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
kuku
Tux's lil' helper
Tux's lil' helper


Joined: 23 Dec 2004
Posts: 142

PostPosted: Sat Jul 13, 2013 3:19 pm    Post subject: [solved]Need help porting /etc/local.d script to systemd Reply with quote

I have an aspire v5 machine with intel graphics. The problem with it is that the function keys for brightness controll doesn't work under linux. On openrc I have used a /etc/local.d script which called a bash script but when moved to systemd I dont know how to do it proper.
Code:
#!/bin/sh
/usr/local/bin/sync-acpi-intel &

and my sync-acpi-intel
Code:
BACKLIGHT_DIR=/sys/class/backlight
ACPI=${BACKLIGHT_DIR}/acpi_video0
INTEL=${BACKLIGHT_DIR}/intel_backlight
 
ACPI_MAX=`cat ${ACPI}/max_brightness`
INTEL_MAX=`cat ${INTEL}/max_brightness`
 
while inotifywait -e modify ${ACPI}/brightness >/dev/null 2>&1; do
    BRIGHTNESS=`cat ${ACPI}/brightness`
    # specially handle maximum value
    if [ ${BRIGHTNESS} == ${ACPI_MAX} ]; then
        INTEL_BRIGHTNESS=$INTEL_MAX
    else
   #logarithmic
   INTEL_BRIGHTNESS=$(echo "2^(${BRIGHTNESS}+1)" |bc)
    fi
    echo ${INTEL_BRIGHTNESS} > ${INTEL}/brightness
done

I tired to run it with something like:
Code:
cat /etc/systemd/system/intel.brightness.service                             
[Unit]
Description=Fix for brightness regulation on some intel based laptops
[Service]
ExecStart=/usr/local/bin/sync-acpi-intel
[Install]
WantedBy=multi-user.target
but it doesn't load proper
Code:

intel.brightness.service    loaded failed failed    Fix for brightness regulation on some intel based laptops


Last edited by kuku on Thu Aug 08, 2013 9:10 pm; edited 1 time in total
Back to top
View user's profile Send private message
ivanoff
n00b
n00b


Joined: 05 Dec 2004
Posts: 41
Location: Toulouse France

PostPosted: Mon Jul 15, 2013 6:04 am    Post subject: Reply with quote

try to get the traces for the service itself :
Code:
 journalctl -u yourservice

Also, verify the termination conditions and service pid check by systemd
http://www.freedesktop.org/software/systemd/man/systemd.service.html
_________________
Linux, because you know what it is doing.
Back to top
View user's profile Send private message
ulenrich
Veteran
Veteran


Joined: 10 Oct 2010
Posts: 1480

PostPosted: Mon Jul 15, 2013 8:57 am    Post subject: Reply with quote

oneshot misssing? For example:
Code:
[Unit]
Description=local.start
After=dhcpcd.service

[Service]
Type=oneshot
ExecStart=/etc/local.d/local.start

[Install]
WantedBy=multi-user.target
Back to top
View user's profile Send private message
kuku
Tux's lil' helper
Tux's lil' helper


Joined: 23 Dec 2004
Posts: 142

PostPosted: Sat Jul 27, 2013 7:58 pm    Post subject: Reply with quote

Thank you for help, I made some changes:
Code:
cat /usr/local/bin/sync-acpi-intel

#!/bin/bash
brightness() {

BACKLIGHT_DIR=/sys/class/backlight
ACPI=${BACKLIGHT_DIR}/acpi_video0
INTEL=${BACKLIGHT_DIR}/intel_backlight
 
ACPI_MAX=`cat ${ACPI}/max_brightness`
INTEL_MAX=`cat ${INTEL}/max_brightness`
 
while inotifywait -e modify ${ACPI}/brightness >/dev/null 2>&1; do
    BRIGHTNESS=`cat ${ACPI}/brightness`
    # specially handle maximum value
    if [ ${BRIGHTNESS} == ${ACPI_MAX} ]; then
        INTEL_BRIGHTNESS=$INTEL_MAX
    else
        #logarithmic
        INTEL_BRIGHTNESS=$(echo "2^(${BRIGHTNESS}+1)" |bc)
    fi
    echo ${INTEL_BRIGHTNESS} > ${INTEL}/brightness
done

}

brightness &

and
Code:

klapa kuku # cat /etc/systemd/system/intel.brightness.service
[Unit]
Description=Fix for brightness regulation on some intel based laptops

[Service]
Type=forking
ExecStart=/usr/local/bin/sync-acpi-intel

[Install]
WantedBy=multi-user.target


but there are still errors
Code:
systemctl status intel.brightness                                                                                                                                             
intel.brightness.service - Fix for brightness regulation on some intel based laptops
   Loaded: loaded (/etc/systemd/system/intel.brightness.service; disabled)
   Active: failed (Result: exit-code) since Sat 2013-07-27 19:55:19 BST; 16s ago
  Process: 9983 ExecStart=/usr/local/bin/sync-acpi-intel (code=exited, status=203/EXEC)

Jul 27 19:55:19 klapa systemd[1]: Job intel.brightness.service/restart finished, result=done
Jul 27 19:55:19 klapa systemd[1]: Converting job intel.brightness.service/restart -> intel.brightness.service/start
Jul 27 19:55:19 klapa systemd[1]: Starting Fix for brightness regulation on some intel based laptops...
Jul 27 19:55:19 klapa systemd[1]: About to execute: /usr/local/bin/sync-acpi-intel
Jul 27 19:55:19 klapa systemd[1]: Forked /usr/local/bin/sync-acpi-intel as 9983
Jul 27 19:55:19 klapa systemd[1]: intel.brightness.service changed failed -> start
Jul 27 19:55:19 klapa systemd[1]: intel.brightness.service got final SIGCHLD for state start
Jul 27 19:55:19 klapa systemd[1]: Job intel.brightness.service/start finished, result=failed
Jul 27 19:55:19 klapa systemd[1]: Unit intel.brightness.service entered failed state.
Jul 27 19:55:19 klapa systemd[1]: intel.brightness.service: cgroup is empty
klapa kuku # journalctl -xn                                                                                                                                                               
-- Logs begin at Sun 2013-07-07 08:25:08 BST, end at Sat 2013-07-27 19:55:35 BST. --
Jul 27 19:55:19 klapa systemd[1]: Got SIGCHLD for process 9983 ((pi-intel))
Jul 27 19:55:19 klapa systemd[1]: Child 9983 died (code=exited, status=203/EXEC)
Jul 27 19:55:19 klapa systemd[1]: Child 9983 belongs to intel.brightness.service
Jul 27 19:55:19 klapa systemd[1]: intel.brightness.service: control process exited, code=exited status=203
Jul 27 19:55:19 klapa systemd[1]: intel.brightness.service changed start -> failed
Jul 27 19:55:19 klapa systemd[1]: Closed jobs progress timerfd.
Jul 27 19:55:19 klapa systemd[1]: Got D-Bus request: org.freedesktop.DBus.Local.Disconnected() on /org/freedesktop/DBus/Local
Jul 27 19:55:35 klapa systemd[1]: Accepted connection on private bus.
Jul 27 19:55:35 klapa systemd[1]: Got D-Bus request: org.freedesktop.DBus.Properties.GetAll() on /org/freedesktop/systemd1/unit/intel_2ebrightness_2eservice
Jul 27 19:55:35 klapa systemd[1]: Got D-Bus request: org.freedesktop.DBus.Local.Disconnected() on /org/freedesktop/DBus/Local
Back to top
View user's profile Send private message
ulenrich
Veteran
Veteran


Joined: 10 Oct 2010
Posts: 1480

PostPosted: Wed Jul 31, 2013 9:56 pm    Post subject: Reply with quote

man systemd.service
Quote:
If set to forking it is expected that the process configured with ExecStart= will call
fork() as part of its start-up. The parent process is expected to exit when start-up is
complete and all communication channels set up. The child continues to run as the main
daemon process. This is the behavior of traditional UNIX daemons.

Where is the setup of your child process?
Wouldn't this fit better:
Type=idle
Back to top
View user's profile Send private message
kuku
Tux's lil' helper
Tux's lil' helper


Joined: 23 Dec 2004
Posts: 142

PostPosted: Thu Aug 01, 2013 8:38 pm    Post subject: Reply with quote

ulenrich wrote:
man systemd.service

Where is the setup of your child process?
Wouldn't this fit better:
Type=idle

I have read a little bit (maybe more of a little) and I found that the thing with
brightness() {
}
brightness &
in bash should work as fork - but maybe not
Back to top
View user's profile Send private message
ulenrich
Veteran
Veteran


Joined: 10 Oct 2010
Posts: 1480

PostPosted: Sat Aug 03, 2013 11:23 am    Post subject: Reply with quote

Now, this is my understanding of the issue

Type=forking
enables systemds monitoring facilities on a service.

Type=simple
shouldn't disallow bash to fork


alternative: Couldn't you make two units
1.brightness-conf.service to generate
/run/brightness.conf
2. brightness.service
Wants=brightness-conf.service
ConditionPathExists=/run/brightness.conf
ExecStart=/usr/bin/brightness --config /run/brightness.conf
Back to top
View user's profile Send private message
kuku
Tux's lil' helper
Tux's lil' helper


Joined: 23 Dec 2004
Posts: 142

PostPosted: Thu Aug 08, 2013 9:09 pm    Post subject: Reply with quote

I've converted this script to a daemon written in python using pyinotify - now it works
Thanks all for help

You can view it on my github
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum