Created
August 26, 2016 06:11
-
-
Save marzzz21/80563914cd168b3857767851894b9fc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_status | |
~ |+ if File.exists?(PID_FILE) | |
~ |+ pid = File.read(PID_FILE).to_i | |
~ |+ check_pid_status(pid) if pid > 0 | |
~ |+ File.delete(PID_FILE) | |
~ |+ end | |
~ |+ end | |
~ |+ | |
~ |+ def check_pid_status(pid) | |
~ |+ Process.kill(0, pid) | |
~ |+ puts "Process(#{pid}) is already running." | |
~ |+ exit(1) | |
~ |+ rescue Errno::ESERCH #do nothing, and continue with the script | |
~ |+ rescue Errno::EPERM | |
~ |+ puts "Process with pid=#{pid} is already running but is owned by a different user" | |
~ |+ exit(1) | |
~ |+ end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment