how to write a system service to auto startup chromium on wayland with non-root user?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to write a system service to auto startup chromium on wayland with non-root user?

1,298 Views
gonewithwind-peter
Senior Contributor I

hi all

I am playing imx8 maaxboard and  iwave boards,

I use the below system service can auto startup chromium on maaxboard wayland with root user, but it's not safe with root user, so I need to startup with non-root user.

I tried to modify it somewhere, but not work. eg , I changed  one of the lines like this :ExecStart=sudo -u myuser /usr/bin/chromium  --gpu-no-context-lost --enable-gpu-rasterization --start-fullscreen --kiosk --no-first-run --incognito http://localhost:3300/rpi.html > /dev/null 2>&1 &

but not work.

 

 

any help?

 

my service ,you can see it's root user with --no-sandbox option :

/etc/systemd/system/chromium.service

works in root user

----

 

Description=launch chromium

 

[Service]

User=root

Environment=DISPLAY=:0

Environment=XDG_RUNTIME_DIR="/run/user/0"

Type=oneshot

ExecStart=/bin/sleep 15

ExecStart=/usr/bin/chromium --no-sandbox --disable-infobars --user-data-dir=/tmp/chromium --gpu-no-context-lost --enable-gpu-rasterization --start-fullscreen --kiosk --no-first-run --incognito http://localhost:3300/rpi.html > /dev/null 2>&1 &

 

[Install]

WantedBy=multi-user.target

 

I  posted my question at here too, I think this is a wayland  system service question.

https://www.element14.com/community/message/302365/l/how-to-write-a-system-service-to-auto-startup-c...

 

 

 

0 Kudos
9 Replies

1,268 Views
Zhiming_Liu
NXP TechSupport
NXP TechSupport

Hi 

 

I add test user to sudo permission and then use your root chromium.service,in test user: sudo systemctl start chromium

 

 

 

Description=launch chromium

[Service]

User=root

Environment=DISPLAY=:0

Environment=XDG_RUNTIME_DIR="/run/user/0"

Type=oneshot

ExecStart=/bin/sleep 15

ExecStart=/usr/bin/chromium --no-sandbox --disable-infobars --user-data-dir=/tmp/chromium --gpu-no-context-lost --enable-gpu-rasterization --no-first-run --incognito http://localhost:3300/rpi.html > /dev/null 2>&1 &

[Install]

WantedBy=multi-user.target

 

 

 

 But it with --no-sandbox

0 Kudos

1,265 Views
gonewithwind-peter
Senior Contributor I

hi @Zhiming_Liu 

Thank you

sorry, I do not  get your idea, you mean it can work with non-root user, 

1. how to add sudo permission to a non-root test user? 

2.what is  final chromium.service ? is it like the below?  Thank you.

 

Description=launch chromium

[Service]

User=root

Environment=DISPLAY=:0

Environment=XDG_RUNTIME_DIR="/run/user/0"

Type=oneshot

ExecStart=/bin/sleep 15

ExecStart=/usr/bin/chromium  --disable-infobars --user-data-dir=/tmp/chromium --gpu-no-context-lost --enable-gpu-rasterization --no-first-run --incognito http://localhost:3300/rpi.html > /dev/null 2>&1 &

#or
ExecStart= sudo /usr/bin/chromium  --disable-infobars --user-data-dir=/tmp/chromium --gpu-no-context-lost --enable-gpu-rasterization --no-first-run --incognito http://localhost:3300/rpi.html > /dev/null 2>&1 &

[Install]

WantedBy=multi-user.target

 

0 Kudos

1,257 Views
Zhiming_Liu
NXP TechSupport
NXP TechSupport

Hi

Here are my commands:

1.

useradd test

2.

passwd test

3.add test user to sudo 

 usermod -G sudo test

4.add below text to /etc/sudoers

%sudo ALL=(ALL:ALL) ALL 

5.reboot board, and login in test user

 

6.My chromium.service

Description=launch chromium

[Service]

User=root

Environment=DISPLAY=:0

Environment=XDG_RUNTIME_DIR="/run/user/0"

Type=oneshot

ExecStart=/bin/sleep 15

ExecStart=/usr/bin/chromium --no-sandbox --disable-infobars --user-data-dir=/tmp/chromium --gpu-no-context-lost --enable-gpu-rasterization --no-first-run --incognito http://localhost:3300/rpi.html > /dev/null 2>&1 &

[Install]

WantedBy=multi-user.target

 

 7. use command sudo systemctl start chromium

0 Kudos

1,255 Views
gonewithwind-peter
Senior Contributor I

@Zhiming_Liu 

Thank you so much.

I mean we do not use the command:sudo systemctl start chromium

to start up chromium (it seems it still manually starts up chromium), just every time reboot or power up the board, the chromium can auto startup.

anyway I will test your command to create the sudo test-user(before I generated the test user in yocto local.conf when building image)

 

0 Kudos

1,252 Views
Zhiming_Liu
NXP TechSupport
NXP TechSupport

@gonewithwind-peter 

 

You can add that command to init.rc , so the chromium will auto startup every time

Tags (1)
0 Kudos

1,230 Views
gonewithwind-peter
Senior Contributor I

@Zhiming_Liu 

sorry, you solution and I both do not work.

 

any suggestion?

Tags (1)
0 Kudos

1,249 Views
gonewithwind-peter
Senior Contributor I

@Zhiming_Liu 

Thank you

 there is no init.rc  in systemctl  services (systemd ?):

-sh-4.4# cd /
-sh-4.4# cd etc/
-sh-4.4# find . -name init.rc
-sh-4.4#

 

before we used init.rc or init.d  (something like that), but now in systemctl service (systemd), I think we can not use it. we only can write xxxx.service to auto start a servce. anyway, let me try.

 

0 Kudos

1,246 Views
gonewithwind-peter
Senior Contributor I

@Zhiming_Liu 

maybe I find a way. I have another service, in the service, it can call a script to start up my configs , I can put into the command :sudo systemctl start chromium  

I will try it. if it works, I will reply here.

0 Kudos

1,277 Views
Zhiming_Liu
NXP TechSupport
NXP TechSupport

Hi

 

I am building chromium and will test auto start service later.

 

BR

Zhiming

0 Kudos