You are viewing a single comment's thread from:

RE: Essential Guide to Becoming a Steem Witness

in #steemhelp9 years ago (edited)

Using Ubuntu's Upstart to Make Steem a Service

This post is an addendum to the essentials document and describes how to use Ubuntu's upstart to make Steem a startup service with minimal fail protection (to restart the service if the process dies or server reboots).

Modifying and Installing The Steem Upstart Script

The full script is provided at the bottom of this post. Save it as "steem.conf". The service will be called "steem".

You will want to change several parts of this script to fit your setup:

  • Change the "author" and email.
  • Change the "chdir" line to the path of your Steem working directory (one directory higher than witness_data_dir).
  • Change the "exec" line to point to your steemd daemon.

Once you have edited the script, copy it as sudoer to the /etc/init directory:

sudo cp steem.conf /etc/init/steem.conf

Starting the Steem Service

The easiest way to start the Steem service (and test your config at the same time) is to simply reboot your computer. It is recommended to go ahead and reboot because you will want to test that the steem service starts on reboot anyway. I reboot like this:

sudo reboot

If you don't wish to reboot, you can do the simple command (ensuring first that all other instances of steemd are stopped)

sudo start steem

You can verify that the steem service is running with this command:

ps aux | grep steemd

Which will give something similar to the following output:

ima@ubuntu:~$ ps aux | grep steemd
root       966  0.5  3.5 607992 141480 ?       Ssl  09:07   4:06 /root/steemd --rpc-endpoint

Testing the Service

The first test should have been when you rebooted to start the steem service.

Let's assume that you your ps output included the line:

root       966  0.5  3.5 607992 141480 ?       Ssl  09:07   4:06 /root/steemd --rpc-endpoint

This means that steemd is running as process 966. Let's kill that process and see if the steem service bounces back. The way to kill process 966 is with this command:

sudo kill 966

Here is my output of the full process. Yours should look similar.

ima@ubuntu:~$ ps aux | grep steemd
root       966  0.5  3.5 607992 141736 ?       Ssl  09:07   4:08 /root/steemd --rpc-endpoint
ima       3130  0.0  0.0  11744   924 pts/1    S+   21:22   0:00 grep --color=auto steemd
ima@ubuntu:~$ sudo kill 966
ima@ubuntu:~$ ps aux | grep steemd
root      3132  0.0  0.3 137676 12268 ?        Rsl  21:22   0:00 /root/steemd --rpc-endpoint
ima       3136  0.0  0.0  11740   932 pts/1    S+   21:22   0:00 grep --color=auto steemd

It looks like success. The steemd daemon respawned as process 3132 within seconds of the kill. You may be wondering what the "ima" lines are in the ps output. Those are simply the grep processes I used to filter the full ps output.

Steem Service Upstart Script

# steemservice - steem daemon service for witness
    
description "Steem"
author "Ima Witness <[email protected]>"

# Stanzas
#
# Stanzas control when and how a process is started and stopped
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on runlevel [016]

# Automatically restart process if crashed
respawn

# Essentially lets upstart know the process will detach itself to the background
# This option does not seem to be of great importance, so it does not need to be set.
#expect fork

# Specify working directory
chdir /path/to/steem/working/dir

# Specify the process/command to start, e.g.
exec /path/to/steem/daemon/steemd --rpc-endpoint 2>>debug.log 1>error.log
Sort:  

interesting article
could go in later, i need time and some good hardware first
thanks!

Great guide!

I used steemychicken1's guide to block all ports except 22 on my witness node. This had the unintended effect of blocking the port that upstart listened on.

A quick scan using netstat allowed me to see that upstart was listening on port 8769. Using the same commands for the guide linked above, I unblocked port 8769 and everything worked.

Thank you!

FYI, Ubuntu 16.x now uses systemd by default in place of upstart.


Permanent switch back to upstart

Install the upstart-sysv package, which will remove ubuntu-standard and systemd-sysv (but should not remove anything else -- if it does, yell!), and run sudo update-initramfs -u. After that, grub's "Advanced options" menu will have a corresponding "Ubuntu, with Linux ... (systemd)" entry where you can do an one-time boot with systemd.

If you want to switch back to systemd, install the systemd-sysv and ubuntu-standard packages.

https://wiki.ubuntu.com/SystemdForUpstartUsers

why the hash rate so low in upstart mode? 1hps!

782782ms th_a witness.cpp:429 on_applied_block ] hash rate: 1 hps