Created
December 13, 2017 06:57
-
-
Save namnv609/cacc249f519166def4123015431b71b8 to your computer and use it in GitHub Desktop.
Docker custom upstart script
This file contains hidden or 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/bash | |
# /root/upstart-script | |
# Add line bellow to /etc/bash.bashrc in Docker container | |
# cat /root/upstart-script | bash | |
is_sudoer() { | |
if [ $UID -ne 0 ]; then | |
echo "Please run this script with sudo permission" | |
exit 1 | |
fi | |
} | |
is_sudoer | |
get_pid() { | |
ps ax | grep "$1" | awk '{print $1}' | |
} | |
is_running() { | |
pid=$(get_pid "$1") | |
kill -0 "$pid" > /dev/null 2>&1 | |
echo $? | |
} | |
nginx=$(is_running "[n]ginx: master") | |
crond=$(is_running "[c]ron") | |
sshd=$(is_running "[s]bin/sshd") | |
if [ "$nginx" -ne "0" ]; then | |
service nginx start | |
fi | |
if [ "$crond" -ne "0" ]; then | |
service cron start | |
fi | |
if [ "$sshd" -ne "0" ]; then | |
service ssh start | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment