L.C. Posted January 2, 2010 Report Posted January 2, 2010 I will pay $5 USD via PayPal or money order to write a very simple Linux shell script and meets the described criteria. The script will be executed through Cron scheduling every minute; the script itself should check to see if said process is running, and if not -- execute it. Simple as that. You will receive payment upon successful completion, which includes testing and examination for quality assurance (integrity, security, and free of bugs and problems). The script will be used to assist BlueT in Linux hosting (provided by L Y N X) in the Subspace realm. Quote
MikeTheNose Posted January 2, 2010 Report Posted January 2, 2010 Are you sure you're not overpaying for a script that is incredibly popular? Quote
»D1st0rt Posted January 2, 2010 Report Posted January 2, 2010 The ideal method to check and restart would depend on the process, some things use pid files and/or have specific scripts or command line arguments to kick them off in the way you want Quote
Gannon8 Posted January 2, 2010 Report Posted January 2, 2010 Doesn't ASSS write it's PID to a file? See, thats how long I have been away from continuum. =P Quote
Samapico Posted January 2, 2010 Report Posted January 2, 2010 I did some bash script at school that parsed the ps output to build a tree of processes, with the parentid's and stuff... It sucked... bash is the worst coding language ever conceived. Part of my linux-hate comes from that class Quote
»Lynx Posted January 2, 2010 Report Posted January 2, 2010 I'll write one later for free once I'm done with this damn database assignment. Quote
»Lynx Posted January 2, 2010 Report Posted January 2, 2010 (edited) Okay, here's a script: #/usr/bin/python #Python Script for L.C. #Saturday Jan 2nd 2010, 23:24 #by Christopher Burke krslynx@gmail.com import os import sys processName = "appName" # the process to check processLocation = "path/to/location" # the path to the application to open application = "nameOfApplication" # the name of the application to open for line in os.popen("ps -A | grep " +processName): fields = line.split() pid = fields[0] if os.path.exists("/proc/" +pid) == False: os.popen(processLocation + application) elif os.path.exists("/proc/" +pid) == True: exit() Test it, and let me know of any errors. You'll need to chmod the script to run it with crontab. Just a note: run this script with the same permission level as the application you're going to be running, otherwise expect /proc issues. Edited January 2, 2010 by Lynx Quote
L.C. Posted January 3, 2010 Author Report Posted January 3, 2010 #/usr/bin/python #Python Script for L.C. #Saturday Jan 2nd 2010, 23:24 #by Christopher Burke krslynx@gmail.com import os import sys processName = "dirserver" # the process to check processLocation = "/home/myusername/4990 dirserver" # the path to the application to open application = "dirserver" # the name of the application to open for line in os.popen("ps -A | grep " +processName): fields = line.split() pid = fields[0] if os.path.exists("/proc/" +pid) == False: os.popen(processLocation + application) elif os.path.exists("/proc/" +pid) == True: exit() ~/4990 dirserver$ ./dirserver.py: command not founde 5:import: unable to open X server `'.import: unable to open X server `'.: command not founde 8:./dirserver.py: line 9: processName: command not found: command not founde 10:./dirserver.py: line 11: processLocation: command not found./dirserver.py: line 12: application: command not found: command not founde 13:./dirserver.py: line 14: syntax error near unexpected token `(''/dirserver.py: line 14: `for line in os.popen("ps -A | grep " +processName): Quote
»Lynx Posted January 3, 2010 Report Posted January 3, 2010 #/usr/bin/python #Python Script for L.C. #Saturday Jan 2nd 2010, 23:24 #by Christopher Burke krslynx@gmail.com import os import sys processName = "dirserver" # the process to check processLocation = "/home/myusername/4990 dirserver" # the path to the application to open application = "dirserver" # the name of the application to open for line in os.popen("ps -A | grep " +processName): fields = line.split() pid = fields[0] if os.path.exists("/proc/" +pid) == False: os.popen(processLocation + application) elif os.path.exists("/proc/" +pid) == True: exit() ~/4990 dirserver$ ./dirserver.py: command not founde 5:import: unable to open X server `'.import: unable to open X server `'.: command not founde 8:./dirserver.py: line 9: processName: command not found: command not founde 10:./dirserver.py: line 11: processLocation: command not found./dirserver.py: line 12: application: command not found: command not founde 13:./dirserver.py: line 14: syntax error near unexpected token `(''/dirserver.py: line 14: `for line in os.popen("ps -A | grep " +processName): Ehrm, afaik you can't ./ execute python scripts, you'll either need to use: $ python script.py from the terminal, or using crontab add the full path to the script, but check permissions to allow write/execute privileges. Here's an example that I just tested to open ChatNut on my Mac: #/usr/bin/python #Python Script for L.C. #Saturday Jan 2nd 2010, 23:24 #by Christopher Burke krslynx@gmail.com import os import sys processName = "chatnut" # the process to check processLocation = "/Users/cpburke/Downloads/" # the path to the application to open application = "SignedChatnut.jar" # the name of the application to open for line in os.popen("ps -A | grep " +processName): fields = line.split() pid = fields[0] print pid if os.path.exists("/proc/" +pid) == False: print "Process was not running, launching..." os.popen(processLocation + application) elif os.path.exists("/proc/" +pid) == True: print "Process was running." exit() Quote
L.C. Posted January 3, 2010 Author Report Posted January 3, 2010 #/usr/bin/python #Python Script for L.C. #Saturday Jan 2nd 2010, 23:24 #by Christopher Burke krslynx@gmail.com import os import sys processName = "dirserver" # the process to check processLocation = "/home/bluetds2/4990_dirserver/" # the path to the application to open application = "dirserver" # the name of the application to open for line in os.popen("ps -A | grep " +processName): fields = line.split() pid = fields[0] if os.path.exists("/proc/" +pid) == False: os.popen(processLocation + application) elif os.path.exists("/proc/" +pid) == True: exit()Does not seem to run, since the process does not appear under ps u. dirserver.py has a CHMOD of 755 (write access all the way). Running it with python dirserver.py. Quote
»Lynx Posted January 3, 2010 Report Posted January 3, 2010 (edited) #/usr/bin/python #Python Script for L.C. #Saturday Jan 2nd 2010, 23:24 #by Christopher Burke krslynx@gmail.com import os import sys processName = "dirserver" # the process to check processLocation = "/home/bluetds2/4990_dirserver/" # the path to the application to open application = "dirserver" # the name of the application to open for line in os.popen("ps -A | grep " +processName): fields = line.split() pid = fields[0] if os.path.exists("/proc/" +pid) == False: os.popen(processLocation + application) elif os.path.exists("/proc/" +pid) == True: exit()Does not seem to run, since the process does not appear under ps u. dirserver.py has a CHMOD of 755 (write access all the way). Running it with python dirserver.py. I guess in that case try: #/usr/bin/python #Python Script for L.C. #Saturday Jan 2nd 2010, 23:24 #by Christopher Burke krslynx@gmail.com import os import sys processLocation = "/home/bluetds2/4990_dirserver/" # the path to the application to open application = "dirserver" # the name of the application to open for line in os.popen("ps -A | grep " +processLocation + application): fields = line.split() pid = fields[0] if os.path.exists("/proc/" +pid) == False: os.popen(processLocation + application) elif os.path.exists("/proc/" +pid) == True: exit() Edited January 3, 2010 by Lynx Quote
L.C. Posted January 3, 2010 Author Report Posted January 3, 2010 (edited) bluetds2@krslynx:~/4990_dirserver$ python dirserver.py bluetds2@krslynx:~/4990_dirserver$ ps u USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND bluetds2 7885 0.0 0.4 3296 1816 pts/1 Ss 00:01 0:00 -bash bluetds2 8232 0.0 0.2 2304 904 pts/1 R+ 02:45 0:00 ps u bluetds2@krslynx:~/4990_dirserver$ python Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> dirserver.py Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'dirserver' is not defined Same error with previous version of script. Edited January 3, 2010 by L.C. Quote
»Lynx Posted January 3, 2010 Report Posted January 3, 2010 (edited) bluetds2@krslynx:~/4990_dirserver$ python dirserver.py bluetds2@krslynx:~/4990_dirserver$ ps u USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND bluetds2 7885 0.0 0.4 3296 1816 pts/1 Ss 00:01 0:00 -bash bluetds2 8232 0.0 0.2 2304 904 pts/1 R+ 02:45 0:00 ps u bluetds2@krslynx:~/4990_dirserver$ python Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> dirserver.py Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'dirserver' is not defined Same error with previous version of script. In the terminal, type: ps -A | grep dirserver That will show the output of the application, provided that it's actually called dirserver in the ps list, if that doesn't work type: ps -A | grep /home/bluetds2/4990_dirserver/dirserver which should defiantly show that it is running, provided it is actually running. If that works, then type this into the terminal: python /path/to/the/location/of/lc.py Do not enter interpretational Python (You should not see >>> anywhere). Edit: Seeing as you're running this on my server (I never noticed) - I'll test it myself. Testing: bluetds2@krslynx:~/4990_dirserver$ ps -A | grep dirserver bluetds2@krslynx:~/4990_dirserver$ python /home/bluetds2/4990_dirserver/dirserver.py Checking if dirserver is running... -- Snrrrub's Directory Server 1.0 started -- Press CTRL+C to exit. bluetds2@krslynx:~/4990_dirserver$ ps -A | grep dirserver 8584 pts/1 00:00:00 dirserver bluetds2@krslynx:~/4990_dirserver$ python /home/bluetds2/4990_dirserver/dirserver.py Checking if dirserver is running... pid for dirserver is 8584 dirserver was running, goodbye! Fully tested, it works. Edited January 3, 2010 by Lynx Quote
»doc flabby Posted January 3, 2010 Report Posted January 3, 2010 (edited) LC i've got a script that does this already, that i use for ssdir.playsubspace.com...i don't want money if you choose this one its too simple to deserve it It doesn't need a cron job either, it restarts the server as soon as it crashes... #!/bin/bash #change to dir server directory cd ~/central for (( ; ; )) #repeat forever do #run dir server mono Central.exe > logall.txt done Edited January 3, 2010 by doc flabby Quote
JoWie Posted January 3, 2010 Report Posted January 3, 2010 asss/scripts/run-asss is a good example that does this without cron Quote
L.C. Posted January 3, 2010 Author Report Posted January 3, 2010 (edited) Command: ps -A | grep dirserverResult: 8584 pts/1 00:00:00 dirserver Command: ps -A | grep /home/bluetds2/4990_dirserver/dirserverResult: Command: ps -A | grep "/home/bluetds2/4990_dirserver/dirserver"Result: Below I am testing to see how well the script functions when you are running multiple but different installations of the same software. Dirserver A on port 4990 (Dirserver B is not running at this point)Command: python /home/bluetds2/4990_dirserver/dirserver.pyResult: Checking if dirserver is running...pid for dirserver is 8584dirserver was running, goodbye! Dirserver B on port 5768Command: python /home/bluetds2/5768_dirserver/dirserver.pyResult: Checking if dirserver is running...pid for dirserver is 8584dirserver was running, goodbye! Dirserver A on port 4990Command: python /home/bluetds2/4990_dirserver/dirserver.pyResult: Checking if dirserver is running...pid for dirserver is 8584dirserver was running, goodbye! LC i've got a script that does this already, that i use for ssdir.playsubspace.com...i don't want money if you choose this one its too simple to deserve it It doesn't need a cron job either, it restarts the server as soon as it crashes... #!/bin/bash #change to dir server directory cd ~/central for (( ; ; )) #repeat forever do #run dir server mono Central.exe > logall.txt done bluetds2@krslynx:~/5768_dirserver$ ./auto-bash: ./auto: /bin/bash^M: bad interpreter: No such file or directory Edited January 3, 2010 by L.C. Quote
»Lynx Posted January 3, 2010 Report Posted January 3, 2010 You're not editing the script. Here's the script simplified a bit more into functions/with full comments so you can understand how everything is working a little easier... You can find this on your server at location "~/4990_dirserver/dirserver.py" #/usr/bin/python #Python Script for L.C. #Saturday Jan 2nd 2010, 23:24 #by Christopher Burke krslynx@gmail.com #2010/Jan/02 - Made edits, made it easier to understand """To Run This Script: open utilities->terminal and execute: $ python /path/to/this_script.py You will need to check that processName variable matches the process that you're _running_, and you will need to make sure that the correct path to the process that you're trying to _run_ is located within the path field on line 23""" import os import sys import subprocess processName = "dirserver" # the process to check def runProcess(): # this function will run the below application # If you want to change what application it opens, change the below path subprocess.Popen(['/home/bluetds2/4990_dirserver/dirserver']) # If you want a script that checks multiple directory servers # (I've got no idea why you'd need this) then I guess that can be arranged. def checkProcess(): """ This function will effectively run ps -A | grep <appname> in the shell - therefore it will be checking if processName is running so for multiple instances, you'll need to edit the processName variable to the closest path possible.""" for line in os.popen("ps -A | grep " +processName): fields = line.split() # This is splitting the output of the above pid = fields[0] # and this is grabbing the leftmost output (pid) print "pid for", processName, 'is', pid # this is non-essential check = os.path.exists("/proc/" +pid) # this part of the script is # checking if a /proc/<pid> folder has been created (ie. if the proc- # ess exists) if check == True: # if the check is true... print processName, "was running, goodbye!" # it was running exit() # so exit else: # otherwise, run the runProcess function, found at line: 12 runProcess() """MAIN""" print "Checking if dirserver is running..." # This line is non-essential checkProcess() # check process runProcess() # run process, check process exits the script first anyway... If you'd like to use doc_flabbys script, you'll need to edit the mono Central.exe > logall.txt line to execute dirserver instead. Quote
Simulacrum Posted January 3, 2010 Report Posted January 3, 2010 Lynx, I think that your script won't run ./ because the first line is missing a ! Quote
L.C. Posted January 3, 2010 Author Report Posted January 3, 2010 # If you want a script that checks multiple directory servers # (I've got no idea why you'd need this) then I guess that can be arranged.I do not need a script for a specific application. The purpose of the script of my request is for general-purpose gameserver hosting. That means it should be a script that works for any application. It should be configurable to a specific gameserver application, in which it will monitor for. Your script appears, to me, as if it were written for only 1 unique instance of a program. It would not work for general purpose because gameservers are generally expected to run multiple installations of the same program. I intend to use this script for anything-on-Linux gameserver hosting as a substitute for ServerDoc/TCAdmin -- neither of which really exist for Linux. Quote
»Lynx Posted January 3, 2010 Report Posted January 3, 2010 (edited) Lynx, I think that your script won't run ./ because the first line is missing a ! You're correct, good catch. If you edit line one to '#!/usr/bin/python' it will run by running /path/to/dirserver.py instead of python /path/to/dirserver.py. Thanks. I do not need a script for a specific application. The purpose of the script of my request is for general-purpose gameserver hosting. That means it should be a script that works for any application. It should be configurable to a specific gameserver application, in which it will monitor for. The script will check if the process is running, and if it's not execute a process. That is exactly what you requested - perhaps if you'd have been more explicit in your requests I wouldn't have needed to waste my time writing scripts that don't actually meet your requirements first time around. Your script appears, to me, as if it were written for only 1 unique instance of a program. It would not work for general purpose because gameservers are generally expected to run multiple installations of the same program. I intend to use this script for anything-on-Linux gameserver hosting as a substitute for ServerDoc/TCAdmin -- neither of which really exist for Linux. As I can't really be bothered to write something that's more intellegent in checking unique processes, I'll tell you that you can solve your issue of running multiple instances of the same software by running each (matching) process in a different user (you've got unlimited user-accounts on my server), then instead of using: for line in os.popen("ps -A | grep " +processName): use: userName = bluetds2 for line is os.popen("ps --User " +userName +" | grep " +processName): Edited January 3, 2010 by Lynx Quote
L.C. Posted January 4, 2010 Author Report Posted January 4, 2010 (edited) The script will check if the process is running, and if it's not execute a process. That is exactly what you requested - perhaps if you'd have been more explicit in your requests I wouldn't have needed to waste my time writing scripts that don't actually meet your requirements first time around.Yes, you are right. This is my fault and I am sorry. I will pay you $5 as originally promised. Please inform me of your PayPal address. Edited January 4, 2010 by L.C. Quote
»Lynx Posted January 4, 2010 Report Posted January 4, 2010 I already said I'll do it for free. Message me if you have any issues with running multiple instances of the same application by running in different logins. Quote
»Maverick Posted January 4, 2010 Report Posted January 4, 2010 Hm Python.I've got one for bash (/bin/sh) if you need it. Quote
Testtube Posted January 4, 2010 Report Posted January 4, 2010 (edited) monit anyone?http://mmonit.com/monit/ Edited January 4, 2010 by Testtube Quote
»Maverick Posted January 4, 2010 Report Posted January 4, 2010 Coding yourself is way more cooler (and way more time consuming) haha Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.