LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-01-2014, 04:41 PM   #1
waiko
LQ Newbie
 
Registered: Jan 2014
Posts: 2

Rep: Reputation: Disabled
Should you run server/background programs as separate users in linux? If so, how?


As a linux newbie that is not familiar with running servers I was hoping for an explanation of how things *should* be done. I've put my background below as plainly as possible just in case my thinking or workflow is not right:
  • I have an old PC with Debian to act as a headless machine running server-type programs (Apache, Solr, Nutch, some java programs etc.).
  • Generally my progress is to login by SSH, and follow the various beginner tutorials to get things running.
  • Things are going fine - most tutorials follow a similar guide like (i) download the files, (ii) unzip to your home directory, (iii) edit the config files, and (iv) run the program.
So far all good from a "try things out" point of view, but it seems strange and wrong that I am just running processes from my login account, and the files just kept in my home dir. Also if I run more than one thing I am using screen or the "&" argument to make them run in the background while I set up other things or edit config files.

Fundamentally, my question is how should things be done for a more permanent solution? Things I have been searching without much luck so far are:
  1. Should I create a new user to run each program, so that whatever I am doing on my own login doesn't interfere with them running?
  2. If yes, is it just the same as creating a new regular user and logging as them in to run the program? Is there another way I should create users to run programs? (It seems strange I would need to remember a bunch of passwords if making regular users.)
  3. Where would the program files be kept? In a new user home directory or in a more generic folder like /bin or /opt (I'm not sure what the various root directories are used for, seems to vary between distributions)?
  4. I noticed some process/program users don't have home directories, or run as 'nobody', so how does this tie in? Should I try to set up things to run like this? Again though, where would the programs files go?
Many thanks for any advice to my confused questions!
 
Old 01-01-2014, 07:58 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Taking Apache as an example:

If you used the pkg mgr to download / install, it would setup a separate user and 'home' dir for you.
This would also setup startup file in the startup dir.

Otherwise, you would indeed do all this yourself.
See the upper part of your /etc/passwd file for other system services eg postfix/sendmail for mail.

NB: I don't have Debian, but I believe the pkg mgr is aptitude/apt-get etc.
The startup dir is probably /etc/rc.d/init.d and associated dirs.

Here's a useful link http://www.linuxtopia.org/online_boo...ion_index.html

HTH & Welcome to LQ


PS: if you use '&' to background a program, its still attached to the terminal and will die whne you exit/logoff. You'll need to prefix with 'nohup' as well, to prevent that eg
Code:
nohup someprog >someprog.log 2>&1 &
A beginners guide to the cmd line http://rute.2038bug.com/index.html.gz

Last edited by chrism01; 01-01-2014 at 08:01 PM.
 
Old 01-01-2014, 08:52 PM   #3
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
If you install a server/service in Debian using apt/aptitude/synaptic it starts automatically after installation. And at the next reboot.

If you have other, non-Debian packages you must manually install the start/stop script in /etc/init.d and tell Debian to start it at the next boot:
Code:
update-rc.d defaults yourscriptname
It will run with root privileges.
I recommend strongly against installing non-Debian packages when a Debian package is available.

For own developed programs it is best to write a start-stop script and follow the same procedure as outlined in the paragraph above. Copy a simple script from /etc/init.d and adapt to your needs. It is a bit more work but it pays off to be systematic.

If your script is really simple and only has to be started and never stopped, add the program start in /etc/rc.local

All these boot-time scripts run with root privileges by default. If you don't want that, use the su command to run it with different privilege levels in the start-up script. Some services run as a certain user. For example, Apache runs as www-data for a good reason.

jlinkels
 
Old 01-02-2014, 05:18 PM   #4
waiko
LQ Newbie
 
Registered: Jan 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you chrism01 and jlinkels!

That all makes sense. The server I am trying to configure specifically is Solr which does not have an associated package to install (e.g. using apt-get), so I guess I am going down the manual route. From your posts I guess it can be broken down into (a) create a new user and (b) set up a startup script in /etc/init.d (or equivalent distribution location) to use su to run the server as the new user (e.g. someone like solr-data)?

I noticed for a web server (I just installed lighttpd), as jlinkels said it runs as www-data rather than as root. I can't see a /home/web-data/ directory, so after looking at the /etc/init.d/lighttpd file, which I guess is the startup script I thought the 'executable files' are in /usr/sbin/lighttpd and the configuration files are in /etc/lighttpd.

Hopefully I'm not jumping to the wrong conclusions, but is /user/sbin the usual place then to put a program's binary files, and then the conf files go in /etc? I would guess then I need to edit the conf files to make sure they know to look in /usr/sbin for the programs.

I guess my question is related to my first post where I wanted to learn if there is a prescribed practice for doing a manual install of a server like program, e.g. how to create the user and where to put the installation files if not its homedir. I looked at linuxtopia but user management seems to apply to real world users, and installations cover mainly using whatever package manager the distribution uses.

Thanks again!
 
Old 01-03-2014, 07:36 AM   #5
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
Quote:
Originally Posted by waiko View Post
Thank you chrism01 and jlinkels!

That all makes sense. The server I am trying to configure specifically is Solr which does not have an associated package to install (e.g. using apt-get),
Solr does have a Debian package:
Code:
jlinkels@donald-pc:/tmp$ apt-cache search solr
chef-expander - systems integration framework - index bridge
chef-solr - manager for search indexes of Chef node attributes using Solr
dovecot-solr - Solr full text search support for Dovecot
libwebservice-solr-perl - Perl interface for the Solr (Lucene) web service
libsolr-java - Enterprise search server based on Lucene - Java libraries
solr-common - Enterprise search server based on Lucene3 - common files
solr-jetty - Enterprise search server based on Lucene3 - Jetty integration
solr-tomcat - Enterprise search server based on Lucene3 - Tomcat integration
python-pysolr - lightweight Python wrapper for quering Apache Solr
Even if the package is outdated and you want the newest version, I'd rather recommend installing Debian Unstable instead of installing manually.

Quote:
Originally Posted by waiko View Post
so I guess I am going down the manual route. From your posts I guess it can be broken down into (a) create a new user and (b) set up a startup script in /etc/init.d (or equivalent distribution location) to use su to run the server as the new user (e.g. someone like solr-data)?
I am not sure if you need to create a new user. Follow the Solr documentation on this. Since it has to search through many documents, extended permissions might be needed for that user.
You would create a script in /etc/init.d. The script is run by root at start-up. But inside the script you determine under which user credentials the server runs.

Quote:
Originally Posted by waiko View Post
I noticed for a web server (I just installed lighttpd), as jlinkels said it runs as www-data rather than as root. I can't see a /home/web-data/ directory, so after looking at the /etc/init.d/lighttpd file, which I guess is the startup script I thought the 'executable files' are in /usr/sbin/lighttpd and the configuration files are in /etc/lighttpd.
Correct

Quote:
Originally Posted by waiko View Post
Hopefully I'm not jumping to the wrong conclusions, but is /user/sbin the usual place then to put a program's binary files, and then the conf files go in /etc? I would guess then I need to edit the conf files to make sure they know to look in /usr/sbin for the programs.
Debian puts normal programs in /usr/bin, and programs intended to be used by the administrator in /usr/sbin. User's own programs are put in /usr/local/bin. There is information available in Google about Debian's standard directory structure. Some programs (like Chrome) are set up in /opt. But not by apt.

jlinkels
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
NAS Server, plus two simultanious separate login points and users - possible? daiblade Linux - Newbie 2 10-22-2009 07:39 PM
gcc: run several programs in background at same time with system or whatever exec ? frenchn00b Programming 3 04-26-2009 07:26 PM
Is it ok to run to separate apache instances on the same server and...? helptonewbie Linux - Newbie 5 06-05-2008 08:35 AM
Run programs in background... Cybers19 Linux - Newbie 1 06-02-2004 04:54 AM
Getting Programs to run for users Saus Linux - Newbie 3 02-28-2001 05:43 PM


All times are GMT -5. The time now is 06:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration