Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
+ Reply to Thread
Results 1 to 11 of 11

This is a discussion on Run Program as Service/Daemon? in the VPS & Dedicated forum
I have the following program I need to have start with the server and incase it crashes have it restart automatically: ./hlds_run -game dod -autoupdate ...

  1. #1
    Loyal Client Pawel Kowalski's Avatar
    Join Date
    Sep 2001
    Location
    Albuquerque NM
    Posts
    1,403

    Run Program as Service/Daemon?

    I have the following program I need to have start with the server and incase it crashes have it restart automatically:

    ./hlds_run -game dod -autoupdate +maxplayers 32 +map dod_avalanche +ip 69.73.160.23 > /dev/null 2>&1 &
    In Windows I could run it as a service. Is something like this possible in linux?

  2. #2
    Ron
    Ron is online now
    Now with 46.3% more slack
    Join Date
    Aug 2002
    Posts
    7,014
    Yes.

    RCs and of course cron jobs. Perhaps you should set up a monitoring service (I think you get some on a VPS?) to watch for and start/restart it automagically?

    This might be dated info and/or UNIX version specific, so it might not be perfect for you.
    Good luck

  3. #3
    Loyal Client Pawel Kowalski's Avatar
    Join Date
    Sep 2001
    Location
    Albuquerque NM
    Posts
    1,403
    Hi Ron,

    I'm not sure I understand what an RC is, tried to google it but couldn't find much info. Cron jobs are set up to run at a certain time aren't they? Or is there a way to make them run on start up?

    The only control panel I got is virtuozzo and I don't see any option there for monitoring a process, just the ability to kill one.

  4. #4
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,985
    RC stands for "run commands." In *nix environments there is usually a directory where you can store references to (symlinks) commands that should start up automatically. This is usually in /etc/rc.d. Inside rc.d there is usually several more directories, such as rc#.d (where # is an actual number) that correspond to different runlevels (or system states). (here is a good explanation of runlevels)

    Inside the rc#.d directory (most system services, including Apache and most other Internet sevices will start at runlevel 3 (or rc3.d) and greater) you will find several symlinks to scripts (usually in rc.d/init.d) with names similar to S85httpd. These are executed in alphabetical order as they system comes up, so the numbers are used to differentiate that one script get run before another--for example, on my VPS, S64mysqld will start before S85httpd. There are also files that start with "K" that indicate the kill order of the processes when the system is being shutdown or rebooted. Pay close attention to these numbers if your process requires other processes to be running or you could have problems.

    Runlevel 6 (rc6.d) is generally the reboot runlevel (entered as the system begins the reboot process) and is used to gracefully stop the services you've started at other runlevels.

    The init.d script is a simple bash script, owned by root, that will receive one of three parameters: start, stop, or restart. Look at some of the other scripts in that directory to get an idea of how to write your own.

    Hope this helps.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  5. #5
    Ron
    Ron is online now
    Now with 46.3% more slack
    Join Date
    Aug 2002
    Posts
    7,014
    ^^^ Wow. What Jason (da man) said.

    About cron jobs:
    You could set up a cron job, a shell script, that looks for a certain process and if it doesn't find it, starts it. You could set that up to run every X minutes. Pick a number for X.

    Also:
    The monitoring service -- doesn't that come with a VPS? If not specifically, couldn't you use some of your free administration time to ask them to write that quick script? (I thought you used to get Level2 management which comes with 5 monitored processes, but the new pages don't talk about it that way. Open a ticket to support and/or sales and ask?)
    Good luck

  6. #6
    Loyal Client Pawel Kowalski's Avatar
    Join Date
    Sep 2001
    Location
    Albuquerque NM
    Posts
    1,403
    Thanks Jason, I finally got a chance to read through this. I think I can get it working, I'll see if I run in to any issues.

  7. #7
    Ron
    Ron is online now
    Now with 46.3% more slack
    Join Date
    Aug 2002
    Posts
    7,014
    I'm officially chopped liver.
    Good luck

  8. #8
    Loyal Client Pawel Kowalski's Avatar
    Join Date
    Sep 2001
    Location
    Albuquerque NM
    Posts
    1,403
    Ron, sorry I didn't respond to you yesterday. I didn't get a chance to look in to shell scripts until this morning and didn't really want to ask you any stupid questions before reading up on it myself (I do that sometimes).

    For obvious reasons having cron restart my process if it crashes would be more worth while than just starting the process at boot time. Based on what you said I found the following tutorial which I think will get me going in the right direction to write the shell script:

    http://www.freeos.com/guides/lsst/

    But what command would I actually use to see if a process is currently running? Thanks.

  9. #9
    Ron
    Ron is online now
    Now with 46.3% more slack
    Join Date
    Aug 2002
    Posts
    7,014
    LOL I really wasn't offended, I just thought that would be funny.

    I used complex products (AutoSys, Tivoli) to monitor my system processes in a production environment. I am really a long time out of writing shell scripts, although I think this would be very easy to do, so let's try:

    Here is a script that might do what you need, where the jobname is hlds_run
    Code:
    #!/bin/bash
    
    ps -ef|grep hlds_run|grep -v grep >/dev/null
    if [[ $? -ne 0 ]]
    then
       # Job not found, so start it
       ./hlds_run -game dod -autoupdate +maxplayers 32 +map dod_avalanche +ip 69.73.160.23 > /dev/null 2>&1 & 
    fi
    Call this file anything other than hlds_run and run it from cron every X minutes.

    Nosing around the 'net I found some info on inittab which might do exactly what you're looking for as well. I don't know if inittab is available for your VPS. If it is, it looks like a line like
    Code:
    Myhlds_run:2:respawn:/path/to/script/hlds_run -game dod -autoupdate +maxplayers 32 +map dod_avalanche +ip 69.73.160.23 > /dev/null 2>&1
    in /etc/inittab might do the trick
    If inittab is not available, perhaps procmon is available on your VPS.
    Good luck

  10. #10
    Ron
    Ron is online now
    Now with 46.3% more slack
    Join Date
    Aug 2002
    Posts
    7,014
    PS -- These methods don't do anything if there's a problem causing your process to crash over and over again. They just restart them when they go down.

    Assuming that you can't modify the code for the game server to say when and/or why it is going up or down, in the cron job script you might wanna stick a line in that writes startup info to a log.
    In the inittab version you might want to put that long command line into a script file, and also put a log write into that. At least you'll know how often a script is being restarted.
    Good luck

  11. #11
    Loyal Client Pawel Kowalski's Avatar
    Join Date
    Sep 2001
    Location
    Albuquerque NM
    Posts
    1,403
    Sweet, thanks. I'll give this a shot once I get the server working properly.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts