Koozali.org: home of the SME Server

[SOLVED] Run script at startup as specific user

[SOLVED] Run script at startup as specific user
« on: July 27, 2016, 05:59:38 PM »
Hello there,

I'd like to run a script at system startup as a particular user. I've tried the SME Crontab Manager, but that only allows timed jobs rather than on reboots.

I looked into using the @reboot option in the main crontab, but that only appears to default to running by the root user.

I also tried to create a crontab for that particular user using 'sudo crontab -u xxxxx', and that didn't work.

Lastly I had a quick look at /etc/init.d/functions but got a bit confused at that point.

What's the best way to do this in SME server?

Thanks!
« Last Edit: August 16, 2016, 06:51:55 PM by Stefano »

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: Run script at startup as specific user
« Reply #1 on: July 27, 2016, 06:04:27 PM »
Please, explain US exactly what you need, thank you

Re: Run script at startup as specific user
« Reply #2 on: July 27, 2016, 06:08:29 PM »
OK -  I have a user on my system, called monitor.

When the system reboots I would like to automatically run this script:

/home/e-smith/files/users/monitor/start_server.sh

I would like it to be run by the 'monitor' user, rather than as root.


Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: Run script at startup as specific user
« Reply #3 on: July 27, 2016, 06:31:58 PM »
What is 'server'?
Is it just a script created by you or something coming with a software?

Re: Run script at startup as specific user
« Reply #4 on: July 27, 2016, 06:35:40 PM »
Hi,

It is just a script created by me. It opens up two detached 'screen' sessions both of which are running python scripts. The script works fine to do this.

This allows me to log in as the 'monitor' user and then reattach to either of the screens to check how things are running.

I know this is not the perfect way to do this, but it would be great if I could get it working for the time being.

Thanks!

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: Run script at startup as specific user
« Reply #5 on: July 27, 2016, 11:00:04 PM »
take a look here, you can use the same approach

https://wiki.contribs.org/Tomcat

Re: Run script at startup as specific user
« Reply #6 on: July 28, 2016, 12:26:22 AM »
Thank you so, so much Stefano - that worked perfectly!

Cheers!

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: Run script at startup as specific user
« Reply #7 on: July 28, 2016, 12:32:59 AM »
you are welcome :-)

BTW, if you find SME useful for you, would you mind to donate something? you can donate time & skills (for development, tests, bugfixing) or money :-)

TIA

guest22

Re: Run script at startup as specific user
« Reply #8 on: August 15, 2016, 05:02:52 AM »
Can this please marked [Solved]?

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: [SOLVED] Run script at startup as specific user
« Reply #9 on: August 16, 2016, 06:52:22 PM »
done