create account

Use Ubuntu Upstart to Make Steem a Service by steemed

View this thread on: hive.blogpeakd.comecency.com

Viewing a response to: @steemed/become-a-steem-witness-essentials

· @steemed · (edited)
$995.47
Use Ubuntu Upstart to Make Steem a Service
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](http://upstart.ubuntu.com/) 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 <ima@imawitness.net>"
    
    # 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
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorsteemed
permlinkuse-ubuntu-upstart-for-steem-service
categorysteemhelp
json_metadata""
created2016-04-23 21:56:21
last_update2016-04-23 21:58:36
depth1
children5
last_payout2016-08-24 21:32:06
cashout_time1969-12-31 23:59:59
total_payout_value497.754 HBD
curator_payout_value497.719 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,910
author_reputation23,215,872,177,290
root_title"Essential Guide to Becoming a Steem Witness"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id669
net_rshares109,710,191,962,442
author_curate_reward""
vote details (48)
@angelblouz ·
interesting article
could go in later,  i need time and some good hardware first
thanks!
👍  
properties (23)
authorangelblouz
permlinkre-steemed-use-ubuntu-upstart-for-steem-service-20171225t023716210z
categorysteemhelp
json_metadata{"tags":["steemhelp"],"app":"steemit/0.1"}
created2017-12-25 02:38:06
last_update2017-12-25 02:38:06
depth2
children0
last_payout2018-01-01 02:38:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length88
author_reputation34,905,385,134
root_title"Essential Guide to Becoming a Steem Witness"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id25,103,799
net_rshares1,148,899,068
author_curate_reward""
vote details (1)
@baryonlee ·
why the hash rate so low in upstart mode? 1hps!

782782ms th_a       witness.cpp:429               on_applied_block     ] hash rate: 1 hps
properties (22)
authorbaryonlee
permlinkre-steemed-use-ubuntu-upstart-for-steem-service-20160822t071852355z
categorysteemhelp
json_metadata{"tags":["steemhelp"]}
created2016-08-22 07:18:51
last_update2016-08-22 07:18:51
depth2
children0
last_payout2016-08-24 21:32:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length138
author_reputation144,042,539,115
root_title"Essential Guide to Becoming a Steem Witness"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id931,043
net_rshares0
@complexring ·
Great guide!

I used [steemychicken1's guide](https://steemit.com/witness-category/@steemychicken1/-iptables-simple-configuration) 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!
👍  
properties (23)
authorcomplexring
permlinkre-steemed-use-ubuntu-upstart-for-steem-service-20160426t012601820z
categorysteemhelp
json_metadata{}
created2016-04-26 01:25:39
last_update2016-04-26 01:25:39
depth2
children0
last_payout2016-08-24 21:32:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length462
author_reputation62,649,292,215,598
root_title"Essential Guide to Becoming a Steem Witness"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id830
net_rshares23,729,474
author_curate_reward""
vote details (1)
@daowisp ·
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
properties (22)
authordaowisp
permlinkre-steemed-use-ubuntu-upstart-for-steem-service-20160815t022813974z
categorysteemhelp
json_metadata{"tags":["steemhelp"],"links":["https://wiki.ubuntu.com/SystemdForUpstartUsers"]}
created2016-08-15 02:28:15
last_update2016-08-15 02:28:15
depth2
children0
last_payout2016-08-24 21:32:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length588
author_reputation2,750,638,235,966
root_title"Essential Guide to Becoming a Steem Witness"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id809,835
net_rshares0
@nextgenwitness ·
$89.67
Thanks for sharing this, adding to my witness!
👍  , , , , , , , , ,
properties (23)
authornextgenwitness
permlinkre-steemed-use-ubuntu-upstart-for-steem-service-20160424t041426566z
categorysteemhelp
json_metadata{}
created2016-04-24 04:14:27
last_update2016-04-24 04:14:27
depth2
children0
last_payout2016-08-24 21:32:06
cashout_time1969-12-31 23:59:59
total_payout_value44.848 HBD
curator_payout_value44.820 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length46
author_reputation9,326,993,992
root_title"Essential Guide to Becoming a Steem Witness"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id693
net_rshares31,582,978,629,650
author_curate_reward""
vote details (10)