Skip to content

Instantly share code, notes, and snippets.

@Sagleft
Last active September 29, 2022 23:25
Show Gist options
  • Save Sagleft/645d094a9f728ae63480347c843b9b11 to your computer and use it in GitHub Desktop.
Save Sagleft/645d094a9f728ae63480347c843b9b11 to your computer and use it in GitHub Desktop.

Autostart Utopia client in Headless Mode using Ubuntu as an example

This may be necessary if you are creating your service (site, bot, etc) for the Utopia Network that will use the Utopia API.

First we install the Utopia client:

apt-get install gdebi-core libx11-xcb1 libgl1-mesa-glx libpulse-mainloop-glib0 libgtk-3-dev
cd /home
mkdir utopiahome
cd utopiahome
wget https://update.u.is/downloads/linux/utopia-latest.amd64.deb
gdebi utopia-latest.amd64.deb

The Utopia client will be installed on the path: /opt/utopia/messenger/.

Go to the folder with the client, create a configuration file (see example below):

nano /home/utopiahome/utopia.cfg

and fill it in:

[General]
apiEnabled=true
apiHTTPEnabled=true
apiHTTPSEnabled=false
apiHelpEnabled=false
apiPort=22824
apiSslPort=10100
apiUserTokens=2FCD80B3113377A7241567A7E8FA637B
applicationLastOpenedPath=account.db
userDatabase=/home/utopiahome/account.db
userPassword=accountpassword

where

  • userPassword - password from the account .db file;
  • userDatabase - absolute path to .db file of the account, relative path will not work;
  • apiUserTokens - tokens for API, come up with any (any). If you use multiple tokens, then separate them with commas. A token is a 32 character long HEX string;
  • apiEnabled - whether the API is enabled;
  • apiHTTPEnabled - do we accept API requests over HTTP?
  • apiHTTPSEnabled - set to false, because requests will be accepted from localhost;
  • apiPort is the port for receiving requests, make sure it is open;
  • apiSslPort - if set to true in the apiHTTPSEnabled parameter, specify here the https port;
  • apiHelpEnabled - if you do not open API help on localhost, you can set it to false.

Creating an .db file for your account:

cd /opt/utopia/messenger
./utopia --headless --create --db=account.db --configPath=/home/utopiahome/utopia.cfg

Create a script to run the client in console mode (headless mode):

cd /home/utopiahome/
nano start.sh

An example of the content:

#!/bin/bash
/opt/utopia/messenger/utopia --headless --configPath=/home/utopiahome/utopia.cfg

The configPath parameter defines the path to the configuration file that we saw above.

Next, we create the client autorun script in console mode. We name it startopia:

touch /etc/systemd/system/startopia.service
chmod 664 /etc/systemd/system/startopia.service
nano /etc/systemd/system/startopia.service

Fill it in:

[Unit]
Description=Utopia Service
After=network.target

[Service]
Type=idle
WorkingDirectory=/opt/utopia/messenger
ExecStart=/opt/utopia/messenger/utopia --headless --configPath=/home/utopia.cfg
Restart=on-failure
RestartSec=3s

[Install]
WantedBy=multi-user.target

Reboot the syystemctl daemon, add the service to the autorun and try to start Utopia:

systemctl daemon-reload
systemctl enable startopia.service
systemctl start startopia.service

If an error occurs, you can view the details through:

systemctl status startopia.service -l

done! You are awesome!

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