Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Monitor Sidekiq up or down with Shell Script.
process='sidekiq' # process name, you can use this to monitor any process
project_path="/home/ubuntu/apps/demo/" # This is the one you got to change on your side for your server.
#change it based on your configs.
start_service="bundle exec sidekiq -d -C /home/ubuntu/apps/demo/config/sidekiq.yml -i 0 -P /home/ubuntu/apps/demo/tmp/pids/ -L /home/ubuntu/apps/demo/log/sidekiq.log"
# Method to simply store last run time in monitor.log file.
function update_last_run() {
current_time=$(date +'%d/%m/%Y %H:%M:%S')
echo "Last run: $current_time" > monitor.log
# Method to start the service, simply we need to navigate to project folder and run the start process command. $? will return status code of last command, if is not equal to zero then some thing went wrong. Successful command will always return 0 as exit code.
function start_service() {
cd $project_path && $start_service
if [ "$?" == "0" ]
echo "$process started successfully"
echo "Could not start process $process"
function check_process()
process_id=$(/bin/ps -fu $USER| grep $process | grep -v "grep" | awk '{print $2}')
echo "checking process $process"
# if $process_id is empty, then it got stopped and you have to start it again
if [ "$process_id" == "" ]
echo "Process is not running"
echo "Starting the process"
echo "Process is running, PID: $process_id"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment