I have a private EOS blockchain setup with peer nodes connected. If any problem occurs and the server gets shut down the nodeos gets stopped (sometimes normally sometimes with dirty flag type errors). And every time I need to restart it manually. Instead, I need that it should get restart as soon as the server gets on. How would I do this? I am using Ubuntu 18.04. Any help would be appreciated.
Nodeos requires that it is shutdown cleanly. Make sure you allow enough time for the state to be written to disk. On a big blockchain with a slow disk, shutdown could take a minute or more.
If you don't shutdown cleanly, then you will need to replay the chain from scratch to rebuild the state or or use a previously saved state snapshot file. More details can be found here: https://developers.eos.io/manuals/eos/v2.0/nodeos/replays/index
To have nodeos start when the server starts, create a systemd unit file or update /etc/rc.local or whatever is your preference for managing system services.
systemd service file as below for running the
biosboot setup files to stop and start nodeos:
[Unit] Description=Stop and Start the eos blockchain After=network.target shutdown.target reboot.target [Service] RemainAfterExit=yes ExecStop=/home/user/biosboot/genesis/stop.sh ExecStart=/home/user/biosboot/genesis/start.sh WorkingDirectory=/home/user/biosboot/genesis [Install] WantedBy=multi-user.target
This service stops the nodeos before the server shutdown/restart and starts after the server gets on.