Koozali.org: home of the SME Server

Obsolete Releases => SME Server 9.x => Topic started by: occasionaltable on July 27, 2016, 05:59:38 PM

Title: [SOLVED] Run script at startup as specific user
Post by: occasionaltable 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!
Title: Re: Run script at startup as specific user
Post by: Stefano on July 27, 2016, 06:04:27 PM
Please, explain US exactly what you need, thank you
Title: Re: Run script at startup as specific user
Post by: occasionaltable 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.

Title: Re: Run script at startup as specific user
Post by: Stefano 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?
Title: Re: Run script at startup as specific user
Post by: occasionaltable 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!
Title: Re: Run script at startup as specific user
Post by: Stefano on July 27, 2016, 11:00:04 PM
take a look here, you can use the same approach

https://wiki.contribs.org/Tomcat
Title: Re: Run script at startup as specific user
Post by: occasionaltable on July 28, 2016, 12:26:22 AM
Thank you so, so much Stefano - that worked perfectly!

Cheers!
Title: Re: Run script at startup as specific user
Post by: Stefano 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
Title: Re: Run script at startup as specific user
Post by: guest22 on August 15, 2016, 05:02:52 AM
Can this please marked [Solved]?
Title: Re: [SOLVED] Run script at startup as specific user
Post by: Stefano on August 16, 2016, 06:52:22 PM
done