You are not logged in.

#1 2019-05-26 18:54:08

Programmer
Member
From: Iran, Tehran
Registered: 2015-04-03
Posts: 39
Website

Make script and run as Service in system startup for i3 config

Hey Guys,
I made a script for some config in my i3 that contains this commend :

path : /usr/bin/startup

#!/bin/bash

### Set Keyboard Layout
exec "setxkbmap -layout us,ir"
exec "setxkbmap -option 'grp:alt_shift_toggle'"

#monitor
xrandr | grep 'HDMI1 connected' &&
    xrandr --output eDP1 --auto --output HDMI1 --auto --left-of eDP1


#set background
 while true; do
        nitrogen --set-zoom --random /home/mehrdad/Pictures/norway/
      sleep 5m
   done

and maybe some another thing later. when I want start this script with "./" I got this error :

./startup: line 4: exec: setxkbmap -layout us,ir: not found

and when try to start that as service :

path : /etc/systemd/system/startup.service

[Unit]
Description=Script

[Service]
ExecStart=/usr/bin/startup

[Install]
WantedBy=multi-user.target

I got this error when check service status :

/etc/systemd/system$ sudo systemctl status startup.service
● startup.service - Script
   Loaded: loaded (/etc/systemd/system/startup.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2019-05-26 18:47:52 UTC; 4s ago
  Process: 2534 ExecStart=/usr/bin/startup (code=exited, status=127)
 Main PID: 2534 (code=exited, status=127)

May 26 18:47:52 mskm systemd[1]: Started Script.
May 26 18:47:52 mskm startup[2534]: /usr/bin/startup: line 4: exec: setxkbmap -layout us,ir: n>
May 26 18:47:52 mskm systemd[1]: startup.service: Main process exited, code=exited, status=127>
May 26 18:47:52 mskm systemd[1]: startup.service: Failed with result 'exit-code'.
lines 1-10/10 (END)

but when I run that lines in terminal , expect "#set background" part, I didn't check it yet in termianl, everything work perfectly.

may please help me


Android, Java And Kotlin Developer
and interested to arch linux, go and rust languages

Offline

#2 2019-05-26 18:58:29

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Make script and run as Service in system startup for i3 config

Why aren't you using xinitrc for this?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2019-05-26 19:04:14

Programmer
Member
From: Iran, Tehran
Registered: 2015-04-03
Posts: 39
Website

Re: Make script and run as Service in system startup for i3 config

jasonwryan wrote:

Why aren't you using xinitrc for this?

thanks for reply jasonwryan,
because make challenge for myself and work with services and systemd deeper to improve my knowledge

Last edited by Programmer (2019-05-26 19:06:50)


Android, Java And Kotlin Developer
and interested to arch linux, go and rust languages

Offline

#4 2019-05-26 19:14:25

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: Make script and run as Service in system startup for i3 config

But it really isn't the correct tool for the job. It's like me asking for the best way to screw things with a hammer.

The best place to put such commands is in your ~/.xinitrc.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#5 2019-05-26 19:21:48

N_BaH
Member
Registered: 2015-12-30
Posts: 84

Re: Make script and run as Service in system startup for i3 config

plus :

$ help exec
exec: exec [-cl] [-a name] [command [arguments ...]] [redirection ...]
    Replace the shell with the given command.

which means the script won't run after first exec command,
and no quotes are required.

Offline

#6 2019-05-26 19:33:41

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: Make script and run as Service in system startup for i3 config

In addition to N_BaH's point, the error message itself is due to the quotes, exce is looking for a callable executable with the name of everything in the quotes - which is nonsense.

Now, wanting to learn to use service files is good, but a omnibus script doing all this different stuff is just not the way to do it.  Put the keyboard mapping and xrandr commands in an xinitrc as noted above.  But the wallpaper setting command is actually and excellent thing to have systemd do: rather than having a shell looping, just use a systemd timer.

Note that you will want it to be a user timer and you'll have to export a DISPLAY variable.  Timers, user services, and exporting variables for systemd services are all well covered in the wiki.  Check out the relevant pages, and set up a wallpaper timer with systemd and you'll have gained worthwhile experience using service files.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB