0

The information on the web regarding upstart, init and .conf files is rubbish. A lot of different places show completely different ways of doing things.

Anyways, I have a script file /home/karl/.scripts/startup/sensei-raw-startup.sh (file permission 775):

#!/bin/bash
# run as root

xinput list >> /var/log/trololol.log

echo trololol start >> /var/log/trololol.log

ids=$(xinput list | awk '/SteelSeries Sensei Raw Gaming Mouse .*pointer/ {print $8}' | sed 's/id=\(.*\)/\1/')

echo trololol before ids >> /var/log/trololol.log
echo $ids >> /var/log/trololol.log
echo trololol after ids >> /var/log/trololol.log

if [ -z "$ids" ]; then
  exit 0;
fi

read -a ids_array <<< $ids

echo fixing id ${ids_array[0]}
xinput set-prop ${ids_array[0]} 'Device Accel Profile' -1
xinput set-prop ${ids_array[0]} 'Device Accel Constant Deceleration' 2.5
xinput set-prop ${ids_array[0]} 'Device Accel Adaptive Deceleration' 1
xinput set-prop ${ids_array[0]} 'Device Accel Velocity Scaling' 1

echo fixing id ${ids_array[1]}
xinput set-prop ${ids_array[1]} 'Device Accel Profile' -1
xinput set-prop ${ids_array[1]} 'Device Accel Constant Deceleration' 1.5
xinput set-prop ${ids_array[1]} 'Device Accel Adaptive Deceleration' 1
xinput set-prop ${ids_array[1]} 'Device Accel Velocity Scaling' 1

sensei-raw-ctl --show
sensei-raw-ctl --polling 500
sensei-raw-ctl --cpi-on 450
sensei-raw-ctl --cpi-off 5670

unset ids
unset ids_array

echo sensei-raw-startup.sh script `date` >> /var/log/sensei-raw-startup.log

echo trololol end >> /var/log/trololol.log

When logged in running the script as sudo it runs perfectly (log is also created):

karl@karl-laptop:~/.scripts/startup$ sudo bash sensei-raw-startup.sh 
fixing id 12
fixing id 14
Backlight intensity: low
Backlight pulsation: slow
Speed in CPI (LED is off): 5670
Speed in CPI (LED is on): 450
Polling frequency: 500Hz
karl@karl-laptop:~/.scripts/startup$ 

Now I wish for this to automatically run whenever I login or the computer starts up (it should affect every user logging in).

I created the file /etc/init/karl-startup.conf:

description "karls sexy startup script"
author "Karl Morrison"

start on started lightdm

pre-start script
        exec xinput 1> /var/log/karls.log 2>&1
end script

script
        exec bash /home/karl/.scripts/startup/sensei-raw-startup.sh
end script

Now I check the file with:

karl@karl-laptop:~$ init-checkconf /etc/init/karl-startup.conf
File /etc/init/karl-startup.conf: syntax ok

I restart my laptop, login and my mouse settings have not been altered, I check the logs:

karl@karl-laptop:~$ sudo cat /var/log/trololol.log 
[sudo] password for karl: 
trololol start
trololol before ids

trololol after ids

As you can see where the ids are supposed to be displayed 12 14 it's blank.

Got me the following error:

karl@karl-laptop:~$ sudo cat /var/log/karls.log
Unable to connect to X server
  • @muru The only reason I have it is to see if the files are actually being run. If they are the logs will appear. Nothing more than that. – Karl Morrison Dec 2 '15 at 4:36
  • I'm not sure what the behaviour of exec is when multiple exec lines are present. That's what script end-script is for. – muru Dec 2 '15 at 4:41
  • @muru Updated question with more info! Seems as if xinput command just will not work under upstart. – Karl Morrison Dec 2 '15 at 4:51
  • Have you set the DISPLAY variable and any other variables that the script needs? – muru Dec 2 '15 at 4:52
  • @muru You are seeing everything I have done :) What must I do with this DISPLAY variable? – Karl Morrison Dec 2 '15 at 4:53
0

The file /etc/init/karl-startup.conf should read:

description "karls sexy startup script"

As you say in your related question you want to start the script on login, further use

start on desktop-session-start

if you want to run it on startup, use

start on startup

exec sudo -u $user /home/karl/.scripts/startup/sensei-raw-startup.sh
exec echo sensei-raw-startup.sh script `date` >> /var/log/karl-startup.log start 

Further details on upstart here: http://upstart.ubuntu.com/cookbook/#id300

  • In this question, I wish for it to start before login. I tried your changes, still no effect :/ – Karl Morrison Dec 2 '15 at 1:41
  • Ok, I see. Well if it's at reboot I suggest you use a cronjob. Check here: askubuntu.com/questions/173924/… – mcantsin Dec 2 '15 at 1:43
  • Ok tried cronjob: sudo cronjob -e and wrote @reboot /home/karl/.scripts/startup/sensei-raw-startup.sh, still does not change settings :/ – Karl Morrison Dec 2 '15 at 2:02
  • if you don't explicitly use bash in front of the path to the script, the file would be executed using sh. I suggest, you use @reboot bash /home/karl/.scripts/startup/sensei-raw-startup.sh – mcantsin Dec 2 '15 at 2:08
  • Ok added bash to the command, still not effecting it! – Karl Morrison Dec 2 '15 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.