webdevRefinery Forum: Run commands on Startup as Certain Users - webdevRefinery Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Rate Topic: -----

User is offline TheMaster 

  • *-c0de master-*
  • Group: Members
  • Posts: 748
  • Joined: 24-May 10
  • LocationAustralia
  • Expertise:HTML,CSS,PHP,Java

Posted 11 August 2012 - 02:55 AM (#1)

Run commands on Startup as Certain Users


Right, so I'm setting up a server, and I want to run things really smoothly.

What I'm doing is make a different user for each thing that needs to be run (one user for web-server, one for no-ip client, etc. etc.)

What I want to do, is start each individual server on startup, and run it as that particular user. Many of the programs need to be executed manually (such as no-ip, bukkit, etc.), so I need a seperate script for each one.

How do I run several different scripts on startup, each as a different/specific user? I've searched around, and I've found a couple of things for running on startup that kinda work, but nothing about individual user account running.

Thanks in advance! :D
0


User is offline TheEmpty 

  • I say words in sequences.
  • Group: Members
  • Posts: 5154
  • Joined: 02-October 10
  • Expertise:HTML,CSS,PHP,Java,Javascript,Python,Ruby on Rails,SQL

Posted 11 August 2012 - 03:50 AM (#2)

What OS is your server? Checkout "initab" although you might want something like monit for this in which case you use `su - user -c 'command'`
Reserved.
0


User is offline TheMaster 

  • *-c0de master-*
  • Group: Members
  • Posts: 748
  • Joined: 24-May 10
  • LocationAustralia
  • Expertise:HTML,CSS,PHP,Java

Posted 11 August 2012 - 04:34 AM (#3)

Oops, forgot to mention OS. It's Ubuntu.

Right now, I've managed to get it working by inserting 'su user -c "command" ', onto the end of /etc/rc.local.

It works, but it's not very comfirgurable (when to run it etc.). I'll have a look into initab and monit. Thanks!
0


User is offline NeilHanlon 

  • Group: Members
  • Posts: 884
  • Joined: 08-July 10
  • LocationRowley, Massachusetts
  • Expertise:HTML,CSS,PHP,Java,Graphics

Posted 11 August 2012 - 08:02 AM (#4)

Take a look at run levels, and also at your /etc/rc.local/ folder.

That's probably what you want.
Thanks,
兄ニール

Website | Blog | @NeilHanlon | About.Me | Facebook | LinkedIn
0


User is offline TheMaster 

  • *-c0de master-*
  • Group: Members
  • Posts: 748
  • Joined: 24-May 10
  • LocationAustralia
  • Expertise:HTML,CSS,PHP,Java

Posted 11 August 2012 - 08:22 AM (#5)

View PostNeilHanlon, on 11 August 2012 - 08:02 AM, said:

Take a look at run levels, and also at your /etc/rc.local/ folder.


There is no rc.local folder.
0


User is offline callumacrae 

  • {{ post.author }}
  • Group: Members
  • Posts: 2862
  • Joined: 20-January 11
  • LocationWarwickshire, England
  • Expertise:HTML,CSS,PHP,Javascript,Node.js,SQL

Posted 11 August 2012 - 09:07 AM (#6)

Just don't shut it down :-D
Front-end developer and writer
Twitter | GitHub | phpBB Contributor and Website Team Member | lynxphp
0


User is offline Ruku 

  • I do Linux and that Internet thing.
  • Group: Members
  • Posts: 1349
  • Joined: 17-April 10
  • Location/root
  • Expertise:HTML,CSS,PHP,Javascript,Python,SQL

Posted 11 August 2012 - 09:22 AM (#7)

I wouldn't recommend editing
rc.local
just in case it does get overwritten by updates (I doubt it will, but it's still a good precaution if you're running important stuff in there). This article explains how the init system works in Debian, but I'm not sure how relevant it'll be to Ubuntu any more given that they're switching to Upstart. I think this documentation is what you're looking for if the Debian way no longer works :)
0


User is offline Lemon 

  • I have a dream...
  • Group: Members
  • Posts: 686
  • Joined: 24-February 11
  • Expertise:HTML,CSS,PHP,Javascript,Node.js,SQL

Posted 11 August 2012 - 01:08 PM (#8)

I do this sort of thing with Supervisor to manage my uWSGI or PHP-FPM processes, as it allows specifying users to run as and works cross-platform as it is not dependent on the current init type used by the system. It's somewhat similar to launchd on the Mac in terms of configuration, as you can specify a number of different activation types and how you want a daemon to be executed in just a small configuration file. Another upside is that it manages logs for you and can auto-restart and process that crashes.
Posted Image
In the end, it's not the years in your life that count. It's the life in your years
0


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users


Enter your sign in name and password


Sign in options
  Or sign in with these services