sh

embluk

·

Swoole Auto Restart

·

SH

·

Total Size: 1.57 KB

·

·

Created: 2 months ago

·

Edited: 2 months ago

#!/bin/bash ulimit -n 100000 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" printf $DIR PROCESS_NAME='Your Process Name' # printf "$PROCESS_NAME\n" pkill -f "$PROCESS_NAME" function clean_up { # Perform program exit housekeeping pkill -f -9 "$PROCESS_NAME" exit } trap clean_up SIGHUP SIGINT SIGTERM php -f "$DIR/path_to_your_http_server_file.php" & while true; do inotifywait -r -m $DIR pkill -f "$PROCESS_NAME" while pkill -0 -f "$PROCESS_NAME"; do sleep 0.5 done printf "\n---\n" php -f "$DIR/path_to_your_http_server_file.php.php" & printf "\n\n\n" done

In the example on the right, the command we want to run is './Swoole_HTTP_Server.sh' or whatever you call the shell script... Make sure you get the path to your PHP file correct or it will not work.

$DIR is just the directory containing this script file (computed automatically, but you can hardcode it if you want).

Use $DIR to specify paths relative to the script's path.The PROCESS_NAME variable is the name of the process to kill and restartYou must ensure your process has the same name each time it runs (we use a file at $DIR/servername to store the name)

Alternatively, you can hard code the PROCESS_NAME on line if you like

Requires inotifywait:

sudo apt-get install inotify-tools

So now when you want to run your Swoole HTTP server you run this script and upon every change, the server will restart. smiley-smile.gif

1 bit

87 views

Are you sure you want to delete?

User Profile Picture

Any issues, just ask :)