Created
May 3, 2019 03:54
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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