Skip to content

Instantly share code, notes, and snippets.

@apisit
Last active March 13, 2018 06:06
Show Gist options
  • Save apisit/6032946900e42e9c0520879e1c29f933 to your computer and use it in GitHub Desktop.
Save apisit/6032946900e42e9c0520879e1c29f933 to your computer and use it in GitHub Desktop.
Shell script to watch neo-cli process and restart it

Create launch.sh

note: change the path to your neo-cli

#!/bin/sh

ps auxw | grep neo-cli | grep -v grep > /dev/null

if [ $? != 0 ]
then
  cd /home/ubuntu/neo-cli/ && screen -d -m -t neo-cli dotnet /home/ubuntu/neo-cli/neo-cli.dll --rpc
fi

make it executable by

chmod u+x launch.sh

Run the script with cron

crontab -e

add these two lines.

@reboot /home/ubuntu/./launch.sh
*/1 * * * * /home/ubuntu/./launch.sh

What it does is

  1. Run launch.sh when the server is restart
  2. Run launch.sh every 1 minute to look for neo-cli process. if it doesn't exist then start it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment