Snott

Category: Blockchain

  • Automating Sia for hosting

    Automating Sia for hosting

    Sia is an Open Source Decentralized storage platform, which splits apart, encrypts, and distributes your files across a decentralized network. Since you hold the keys, you own your data. No outside company can access or control your files, unlike traditional cloud storage providers.

    Below is a quick and simple way to integrate siad (the process sia runs) with systemctl, so that you can control it from within systemd the normal way you control the rest of your processes on a Linux System.

    Systemd unit file (put this in /usr/lib/systemd/system/sia.service):

    [Unit]
    Description=Sia daemon
    After=network.target
    
    [Service]
    Type=simple
    User=sia
    Nice=5
    # WorkingDirectory may not be required but to be sure.
    WorkingDirectory=/sia
    # This could be more dynamic, but if we don't limit this, we will get swap problems.
    # Legacy setting for use with cgroups v1.
    MemoryLimit=3.5G
    # Unified hierarchy, supported starting with systemd 231 and later, while CentOS 7 uses 219.
    #MemoryHigh=3G
    #MemoryMax=3.5G
    # Introduced with systemd 232 while CentOS 7 uses 219.
    #MemorySwapMax=0
    ExecStart=/sia/siad --sia-directory /sia
    Restart=on-failure
    RestartSec=30
    
    [Install]
    WantedBy=multi-user.target
    ---
    
    Do systemctl edit sia, an editor will open, add the following:
    [Service]
    Environment="SIA_WALLET_PASSWORD=word1 word2 whatever etc omg lol rofl lmao"
    
    That will make the environment variable accessible from the service so that the wallet is auto-unlocked every time the service starts
    Now you can do "systemctl status|start|stop|restart sia" and if the process fails it will restart by itself within 30 secs.