Last active
October 7, 2022 16:52
-
-
Save rajathithan/13fac6ee23f59702bbe789d85941d242 to your computer and use it in GitHub Desktop.
startupscript
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/bash | |
# Author - Rajathithan Rajasekar | |
# install gcp logging agent | |
curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh | |
sudo bash install-logging-agent.sh | |
# setup a configuration for startup-script logs only | |
sudo cat > /etc/google-fluentd/config.d/service-now-test.conf <<- EOM | |
<source> | |
@type tail | |
# Format 'none' indicates the log is unstructured (text). | |
format none | |
# The path of the log file. | |
path /tmp/service-now-test.log | |
# The path of the position file that records where in the log file | |
# we have processed already. This is useful when the agent | |
# restarts. | |
pos_file /var/lib/google-fluentd/pos/service-now-test.pos | |
read_from_head true | |
# The log tag for this log input. | |
tag service-now-test | |
</source> | |
EOM | |
# startup-script content | |
# ... | |
sudo cat > /etc/init.d/service-now-test.sh <<- EOF | |
#! /bin/bash | |
while true; do | |
sleep 60 | |
echo "Cloud router is down" >> /tmp/service-now-test.log | |
sleep 300 | |
echo "Cloud router is up" >> /tmp/service-now-test.log | |
sleep 300 | |
done | |
EOF | |
sudo chmod +x /etc/init.d/service-now-test.sh | |
#sudo update-rc.d /etc/init.d/service-now-test.sh defaults | |
#(crontab -l 2>/dev/null; echo "@reboot /etc/init.d/service-now-test.sh") | crontab - | |
sudo cat > /etc/logrotate.d/service-now-test <<- EOF | |
/tmp/service-now-test.log | |
{ | |
rotate 1 | |
daily | |
missingok | |
notifempty | |
delaycompress | |
compress | |
postrotate | |
endscript | |
} | |
EOF | |
# restart logging agent | |
sudo service google-fluentd restart | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment