Skip to content

Instantly share code, notes, and snippets.

@hskang9
Last active July 7, 2019 08:41
Show Gist options
  • Save hskang9/4def7c5d3e83cfcb92f2ed4d83ce9441 to your computer and use it in GitHub Desktop.
Save hskang9/4def7c5d3e83cfcb92f2ed4d83ce9441 to your computer and use it in GitHub Desktop.
failsafe script daemon for systemctl
# How to setup
# 1. sudo vi /lib/systemd/system/{service name}.service and copy/paste this code as a starter
#
# 2. Configure log folders and user to execute the command and give access with following commands
# sudo chmod 755 /lib/systemd/system/{service name}.service
#
# 3. Configure systemctl to register the service in the system as start script with `enable`
# sudo systemctl enable {service name}.service
#
# 4. `start` service to test registered service scripts
# sudo systemctl start {service name}
#
# 5. Restart node and check process happening in each port
# lsof -i
#
# 6. kill process and test if the script still works
# kill {pid found in port from lsof -i command}
[Unit]
Description=command for running the cosmos node after restart.
ConditionPathExists=/home/ubuntu/go/bin/gaiad
After=network.target
[Service]
Type=simple
User=ubuntu
Restart=on-failure
RestartSec=10
startLimitIntervalSec=60
WorkingDirectory=/home/ubuntu/go/src/github.com
ExecStart= /home/ubuntu/go/bin/gaiad start --home=/home/ubuntu/.gaiad &> gaia2.log & NODE1_PID=$!
PermissionStartOnly=true
ExecStartPre=mkdir -p /var/log/cosmos
ExecStartPre=chown syslog:adm /var/log/cosmos
ExecStartPre=chmod 755 /var/log/cosmos
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=cosmos
[Install]
WantedBy=multi-user.target
@hskang9
Copy link
Author

hskang9 commented Jun 4, 2019

to Look at status run command and tail the log
sudo journalctl -f -u failsafe

@lingqingmeng
Copy link

to Look at status run command and tail the log
sudo journalctl -f -u failsafe

sudo journalctl -f -u cosmos-failsafe.service

Is what we have to run now

@hskang9
Copy link
Author

hskang9 commented Jul 7, 2019

yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment