Chapter 3

Running as Service

You can run goshs as systemd service easily.

Step 1

You need to create the config file. I suggest creating it in /etc/goshs/.

sudo mkdir -p /etc/goshs

Now copy over the example config as goshs.json and configure the way you like.

Warning

You will at least need to configure a directory to serve from. For example you could choose /var/www/html if available. You could also create this webroot with sudo mkdir -p /var/www/html and serve from there.

Step 2

Create a systemd service. You can use the example service and copy it to /etc/systemd/system/goshs.service.

[Unit]
Description=goshs File Server
After=network.target

[Service]
ExecStart=/usr/local/bin/goshs -C /etc/goshs/goshs.json
Restart=on-failure
User=www-data
Group=www-data

[Install]
WantedBy=multi-user.target
Warning

Be sure to match the path to the goshs binary. Putting it to a location like /usr/local/bin/ will ensure that a user like www-data can read and execute it. Be sure to change the user and group accordingly.

Now all that is left to do is reload the daemon as well as starting and enabling the service.

sudo systemctl daemon-reload
sudo systemctl start goshs.service

Go and check if the service is running correctly:

sudo systemctl status goshs.service

● goshs.service - goshs File Server
     Loaded: loaded (/etc/systemd/system/goshs.service; disabled; preset: enabled)
     Active: active (running) since Thu 2024-07-04 18:01:46 CEST; 8s ago
   Main PID: 14205 (goshs)
      Tasks: 10 (limit: 7680)
     Memory: 7.5M
        CPU: 80ms
     CGroup: /system.slice/goshs.service
             └─14205 /usr/local/bin/goshs -C /etc/goshs/goshs.json

...

If so you can enable the service so it starts at boot time.

sudo systemctl enable goshs.service

Created symlink /etc/systemd/system/multi-user.target.wants/goshs.service → /etc/systemd/system/goshs.service.