LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices



Reply
 
Search this Thread
Old 04-05-2011, 08:58 PM   #1
yanom
Member
 
Registered: Apr 2011
Distribution: Ubuntu
Posts: 51

Rep: Reputation: 2
Run a program in the background


Is there a way to make a program (a Minecraft server in this instance) run in the background, from when the computer starts up to when it shuts down, regardless of who (if anyone) is logged in? The people who log in shouldn't see any output or offer any input to the program.
 
Old 04-05-2011, 10:14 PM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,154

Rep: Reputation: 333Reputation: 333Reputation: 333Reputation: 333
Many ways. If it's a "server," is it intended to interact with a specific user, or with every system user? (If it's every user, look a the dbus system.) If it's a specific user, you could just start it from a script and issue a disown command before exiting. Here's a function I use to start my WiFi connection before the X-server is started as an example of the technique.
Code:
#############################################################################
#
# Connect to the specified network if it's available
#
# Arguments:
#  $1 - Access point
#  $2 - Passphrase (If blank, use contents of /root/.connect_passphrase)
#  $3 - Connection type {unprotected|wep|wpa} Default: wpa
#       Note: Only passphrase WEP ans WPA encription is supported
#             by this script
#
#############################################################################
connect_to() {
  local we type pass i
# Get the list of available access points
  we=$(cnetworkmanager --we)
  if [ -z "${we}" ]
  then 
    echo "No wireless devices are available on this system."
    return 1
  fi
  [ -z "${1}" ] && echo "Required argument missing." && return 2
  [ -z "${pass}" ] && pass=$(cat /root/.connect_passphrase)
  type=$3
  [ -z "${type}" ] && type=wpa
  case ${type,*} in
    unprotected)pass="";;
    wep) type=wep-pass;;
    *) type=wpa-pass;;
  esac
  echo -n "Connecting to ${1}"
  cnetworkmanager -C ${1} --${type} ${pass} &>/dev/null &
  pid=$!
  if [ $? -ne 0 ]
  then
    echo " Unable to connect to ${1}."
  else
    for ((i=1; i<6; i=++i))
    do
      sleep 1
      echo -n " ."
    done
    echo
    echo "Connected to ${1}"
  fi
  disown ${pid}
}
 
Old 04-06-2011, 07:38 PM   #3
yanom
Member
 
Registered: Apr 2011
Distribution: Ubuntu
Posts: 51

Original Poster
Rep: Reputation: 2
Actally, its a game serverr that interacts with other people on other computers over the internet. It doesnt need to interact with anyone on the computer it,s running on. It needs to run if no one is logged in, and still run if someone is
 
Old 04-08-2011, 12:14 AM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,154

Rep: Reputation: 333Reputation: 333Reputation: 333Reputation: 333
So you're going to leave a process running that "reacts" to Internet events. Is it listening to a specific port, and does it require a user ID before responding? (I.e., if not done right, your system will soon belong to the "script kids.")

Anyhow, there are, as I noted above, many ways to do this. The one I suggested was intended for running a background process for a system, not a Web server.

If you're setting up a Web game server, Goggle is your friend. Try this one or, if you read German, this one.

Last edited by PTrenholme; 04-08-2011 at 10:50 AM.
 
  


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
Alias to run a program in the background diamond_D Linux - Newbie 3 05-04-2012 06:04 PM
run program in background karabaja4 Linux - Newbie 3 01-05-2008 01:57 PM
how to run any binary in background - background process tej Linux - Newbie 1 08-16-2004 01:27 AM
Run a program in the background??? KaptinKABOOM Linux - Software 5 07-06-2004 07:40 AM
Program In background frankprogramer Linux - Software 1 10-30-2002 03:56 PM


All times are GMT -5. The time now is 03:31 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration