3

Quick question, is it possible to run as non-root for applications, automatically started when the pi is booted?

I'm having performance and memory issues when my pi starts a homebrewn spotify-client on boot.

Performance - I cannot explain why this is different than when running it from a terminal once logged in, but the music lags a second once every 15-30 seconds.

Memory - My offline tracks doesn't get saved from session to session.

This leads me to the question, can I 'fake' a user logging in and starting the app with user-previlegies?

Right now i'm using /etc/rc.local to run the command /home/pi/spotifyapp & Everything runs smooth and offline tracks are saved when i start the app by myself after the pi has booted

13

I am skeptical whether running this application under a different user will resolve your issue.

However that being said, you can use the su command to run a command as another user. Therefore to run /home/pi/spotifyapp you should use the following in your rc.local file:

su fakeuser -c '/home/pi/spotifyapp &'

You may want to redirect stdout and stderr to a file to allow you to see any messages generated. The following command will do that:

su fakeuser -c '/home/pi/spotifyapp >> /tmp/spotifyapp.log 2>&1 &'

Where fakeuser is the username that you want to run the process under.

| improve this answer | |
  • 1
    Changing the current directory, i.e. cd /home/pi/app/ and then running it as a another user seems to solve the problem. Didn't know that trick, thanks a lot :-) – Allan Nørgaard Jun 27 '13 at 8:03
2

Usually, scripts in /etc/rc.d are using start-stop-daemon to launch, stop and control status of boot-time processus.

Combined with the optional -c, --chuid argument, you can specify under which user you want the process to run.

| improve this answer | |
1

I use

sudo -u yourusername command -parameter
| improve this answer | |
0

You could place your script at the bottom of /etc/profile file.

| improve this answer | |
  • I don't think this would have solved my problem, since I had performance issues. Your answer is about starting a process once logged in. Also, you're 3 years late to the party :) – Allan Nørgaard Nov 28 '16 at 8:00
  • 1
    I've browsed around and just throwing my thoughts into it. Maybe helps someone in the future. – HelpNeeder Nov 29 '16 at 15:18
0

Much like OP (although 7 years later :)) I also wanted to start a service as a nonroot user at startup:

In my case I needed method run a script as the raspotify user at startup so I could automate control of alsamixer and alsaequal from the hardware I had built. However the other answers didn't work for me (in particular the rc.local failed to launch the script and left nothing in the log). (I have added the detail given due to similarity with OP and that this post was the closest search hit while I was working the problem)

Ultimately, I followed the tutorial here and made a systemd service that looked like this:

[Unit]
Description=raspotify_alsaequal_wrapper service.

[Service]
Type=simple
User=raspotify
Group=raspotify
ExecStart=/usr/bin/python /home/pi/alsa_wrap_script

[Install]
WantedBy=multi-user.target

I saved the file at /lib/systemd/system/alsawrap.service and /etc/systemd/system/alsawrap.service

set permissions to 644 and enabled it to start with sudo systemctl enable alsawrap

| improve this answer | |

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.