How to start/end a background process from PHP/bash script?

juuga

I have a service where I list Twitter accounts and have a switch to enable/disable a Streaming API connection for them.

Currently I'm planning to have this flow:

  • User enables a Twitter account for Streaming
  • An email is sent to an admin with cli access on the server, who launches a Phirehose process for that account.
  • (A cron job takes a list of Twitter accounts that have Streaming enabled and checks if a process exists for them. If not, it sends an email to the admin who can relaunch it.)

I would like to launch a Phirehose process directly to run in the background when a user wants a Twitter account to be enabled for Streaming. Also I would like to kill the process directly if a user wants to stop Streaming for that account.

There are several risks and concerns with executing the Phirehose process and especially killing it in an automated way.

Any tips on the best way to implement this with maximal automation and minimal admin interference?

user3593520

I have done similar things with a two step process: part one is to create a web interface that provides start / stop commands. The web interface writes a file to the server. one for start, one for stop. start.lock, stop.lock.

the second part is a bash script that looks for the presence of these files. Below is an example of the start.sh script that would check to start the service. It creates a a "running.lock" file to know not to try to start a running service. You cazn also use the files for reporting purposes.

stop.sh and start.sh are cron scheduled to run frequently. For my purpose, they run every minute and the loop in the script is used to check more frequently. ie, each minute run and check 5 times once every ten seconds.

I think with this you can modify to your specific needs. Hope it helps.

#!/bin/bash

for ((c=1; c<=5; c++))
do

file="start.lock"
if [ -f "$file" ]
then
        sfile="running.lock"
        if [ ! -f "$sfile" ]
        then
                <command goes here>
                touch running.lock
                rm start.lock
        fi

fi

sleep 10
done

and to stop it:

#!/bin/bash

for (( c=1; c<=11; c++ ))
do
file="stop.lock"
if [ -f "$file" ]
then
        killall -9 <your service>
        rm running.lock
        rm start.lock
        rm stop.lock
fi
sleep 5
done

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

pidof from a background script for another background process

From Dev

pidof from a background script for another background process

From Dev

Run a process in background from a unix sh script

From Dev

Forcing a process to background from bash script

From Dev

Run node as background process from script running as child process

From Dev

Run node as background process from script running as child process

From Dev

Start a background process from a script and manage it when the script ends

From Dev

bash script with background process

From Dev

Check running status of a background process launched from same bash script

From Dev

How to detect if python script is being run as a background process

From Dev

Running ssh script with background process

From Dev

How to start java process if it die from script

From Dev

How to execute a shell script in the background from a Python script

From Dev

How to terminate a background process?

From Dev

Android OpenCV - How to process camera frames from background service?

From Dev

How can I launch Chrome as a background process from the command line?

From Dev

Running a process in the background as part of a longer script

From Dev

Execute background process after script has exited

From Dev

Running Python Script as a Windows background process

From Dev

Shell Script: Sending input to background process

From Dev

Execute background process after script has exited

From Dev

Running a script when background process crashes

From Dev

Bash Script to start "orphan" background process

From Dev

Creating a portable background process script with Python

From Dev

how to get the background process id from arr file and kill the process in android

From Dev

How to access page variables from Chrome extension background script

From Dev

Firefox extension - How to show text to user from background script?

From Dev

How to run a python script in the background from my discord bot

From Dev

How to run a python script in the background from my discord bot

Related Related

  1. 1

    pidof from a background script for another background process

  2. 2

    pidof from a background script for another background process

  3. 3

    Run a process in background from a unix sh script

  4. 4

    Forcing a process to background from bash script

  5. 5

    Run node as background process from script running as child process

  6. 6

    Run node as background process from script running as child process

  7. 7

    Start a background process from a script and manage it when the script ends

  8. 8

    bash script with background process

  9. 9

    Check running status of a background process launched from same bash script

  10. 10

    How to detect if python script is being run as a background process

  11. 11

    Running ssh script with background process

  12. 12

    How to start java process if it die from script

  13. 13

    How to execute a shell script in the background from a Python script

  14. 14

    How to terminate a background process?

  15. 15

    Android OpenCV - How to process camera frames from background service?

  16. 16

    How can I launch Chrome as a background process from the command line?

  17. 17

    Running a process in the background as part of a longer script

  18. 18

    Execute background process after script has exited

  19. 19

    Running Python Script as a Windows background process

  20. 20

    Shell Script: Sending input to background process

  21. 21

    Execute background process after script has exited

  22. 22

    Running a script when background process crashes

  23. 23

    Bash Script to start "orphan" background process

  24. 24

    Creating a portable background process script with Python

  25. 25

    how to get the background process id from arr file and kill the process in android

  26. 26

    How to access page variables from Chrome extension background script

  27. 27

    Firefox extension - How to show text to user from background script?

  28. 28

    How to run a python script in the background from my discord bot

  29. 29

    How to run a python script in the background from my discord bot

HotTag

Archive