Posted on 14 Comments

Raspberry Pi – Running Spy Server as a service

  • Updated 8th March to clarify the requirement for Spy Server to be pre-installed.
  • Updated 8th Aug 2018 to add a start-up delay to the rtlsdr.service file. This is to ensure that an IP address has been allocated before the Spy Server starts.

The excellent Airspy Spy Server can easily be used as a service using SYSTEMD under Linux. This is a much better way to autostart the server as it gives you the facility to stop/start/check status of the server at any time. I’ve used this facility in my latest Spy Server SD card so you can switch between receiver types without having to reboot the Pi.

NB: These instructions assume that you already have Spy Server installed and working on your Pi. If you haven’t, see my installation post.

Running Spy Server as a Service

The first step is to create a new file called spyserver.service and save it in /etc/systemd/system/.

The simplest way to do this is using nano as follows:

sudo nano /etc/systemd/system/spyserver.service

Now enter the following text into the file and save it (Ctl x y Enter):

[Unit]

Description=Spy Server

Wants=network-online.target
After=network-online.target

[Service]

ExecStartPre=/bin/sleep 15

ExecStart=/home/pi/./spyserver spyserver.config

WorkingDirectory=/home/pi/

StandardOutput=inherit

StandardError=inherit

Restart=always

User=pi

[Install]

WantedBy=multi-user.target


You can now start, stop and check the status of Spy Server with the following commands:

sudo systemctl start spyserver.service

sudo systemctl stop spyserver.service

sudo systemctl status spyserver.service

The following command will activate the service to automatically start at boot time:

sudo systemctl enable spyserver.service

That’s it!

Mike – G4WNC

14 thoughts on “Raspberry Pi – Running Spy Server as a service

  1. Thanks a lot for the page Raspberry Pi – Running Spy Server as a service
    its working great with Ayrspy mini on a Raspberry Pi 3 +

    for me it did not autostart the service until i googled and found there is an error
    on your page

    wantedBy=multi-user.target must be WantedBy=multi-user.target

    nice work thank you

    1. Hi Fernando,

      Glad you’ve found it useful and thanks for spotting that typo. I’ll correct it now.

      Mike – G4WNC

  2. Mike, with the “Update All” command, will only Linux OS updated or also to the newest Spy server version?

    73 Chris DL5NAM

    1. Hi Chris,

      Apologies for the confusion but ‘Update All’ only updates the spy server code and its associated drivers, i.e. rtl-sdr, airspy and airspy HF+.

      If you want to update the OS, you can use the normal sudo apt update && sudo apt -y upgrade.

      Regards,

      Mike – G4WNC

      1. Mike thanks info, sounds good for me if Spy Server updated with this task.

        OS updated is not so important 🙂

        73 Chris DL5NAM

  3. Thank you.
    I used this method for more than spy server .

  4. Thanks for this!

    I had to modify to provide the full path for my config file, but other than that this worked perfect!

    1. Glad to hear it worked. Thanks for letting me know.

      Mike

  5. Thank you so much for this. I modified the config you provided to use my own username rather than the default ‘pi’ account (e.g. changing the paths to the executables, etc.). It would not work properly until I added my account to the plugdev group (‘sudo usermod -a -G plugdev [username]’). This may be of use to someone else trying to solve this issue.

    1. Hi Ben,

      Glad you found the post useful. Thanks for sharing your username solution.

      Regards,

      Mike – G4WNC

  6. Hi, This works well and I can connect to my Spyserver but I have an issue where it does not get listed on the SpyServer Directory here: https://airspy.com/directory

    When I manually start spyserver it shows on the directory.

    Any ideas?

    1. Hi Graham,

      Not encountered that before. There is a switch near the top of the spyserver.config file that controls directory listing. Are you using the same config file in both cases? You can force the use of a specific config file by specifying it after the run command like so:
      ./spyserver spyserver.config

      It might also be worth checking the process user in each case. You can see the user by opening Task Manager from the Accessories menu. The process user is normally shown in the second column. If you don’t see it, click ‘more details’ at the bottom.

      Let me know how you get on.

      Mike – G4WNC

  7. Thanks for your help, it worked fine for me.
    However, what should we put in the “sudo nano /etc/systemd/system/spyserver.service” file when we want to launch a second airspy or rtlsdr at startup ?

    1. Hi Eric,

      I’ve not tried running two instances of the server. I’ll try it out next week when I get back in the shack. Here’s a couple of thoughts if you want to experiment.

      1 – You will need to create two spyserver.service files and matching spyserver.config files.
      2 – In the config files, you will need to specify a different port for each instance
      3 – You may have the limit the bandwidths available from each instance. Even a Pi4 won’t be able to process two lots of 8MHz Airspy bandwidth!

      Mike – G4WNC

Leave a Reply to Mike Richards Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.