Skip to content

Instantly share code, notes, and snippets.

@DeruiDENG
Created May 3, 2019 03:54
Show Gist options
  • Save DeruiDENG/1ab756ecac5e3a6611cfdc71774145b9 to your computer and use it in GitHub Desktop.
Save DeruiDENG/1ab756ecac5e3a6611cfdc71774145b9 to your computer and use it in GitHub Desktop.
A shell script that can integrate with crontab to keep ss container alive
#!/bin/sh
ssContainer=""
get_ss_container(){
ssContainer="$(sudo docker container list --all | grep shadowsocks)"
}
# Return 0 if ssContianer is UP
get_ss_status()
{
isUp="$(echo $ssContainer | grep Up)"
if [ -n "$isUp" ] ; then
return 0
else
return 1
fi
}
log(){
echo "`date -u`: $1" >> /var/log/ss.log
}
restart_ss(){
containerId=$(echo $ssContainer | awk '{print $1}')
sudo docker container start $containerId
log "SS container has been restarted"
}
get_ss_container
get_ss_status
isUp=$?
if [ $isUp -eq 1 ]
then
restart_ss
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment