How To: Configure Synergy Client systemd Service Auto-Start in Linux (Fedora 20)

Edit (2014-07-02): I would like to thank David for commenting and pointing out some small typos and errors in commands and files.

I was looking for a solution to the following problem:

  1. I wanted the Synergy client process (synergyc) to start on boot so I could use the mouse and keyboard from another computer to enter the log in credentials at the graphical log in screen on my Fedora desktop.
  2. I wanted synergyc to be run as a background service that would automatically restart itself if it crashed for whatever reason.
  3. I wanted synergyc to not be running as the root user whenever possible.

TLDR:

The solution for the above requires that you create a systemd system service for synergyc, edit the file /etc/gdm/PreSession/Default to kill all synergyc processes, create a systemd user instance service for synergyc, and create the file ~/.config/autostart/synergyc.desktop to start the systemd user instance service for synergyc.  Skip to the directions section for specific instructions

TABLE OF CONTENTS:

  1. TLDR
  2. BACKGROUND
  3. DIRECTIONS
    1. Install and Configure Synergy
    2. Create systemd Service for synergyc
    3. Make System Kill Initial synergyc Process Upon Login
    4. Verify systemd User Instance Starts on Boot
    5. Create User Instance synergyc.service File
    6. Create synergyc.desktop Autostart File
  4. Wrapping Up
  5. References

BACKGROUND

I love Synergy!  For those of you who do not know what it is, Synergy is a software based KVM switch; it allows you to use the keyboard and mouse that are plugged in to one computer to control other computers on your network.  So for instance I have three computers running at the same time right now (from left to right) – personal-laptop, personal-desktop, work-laptop.

My Computer Desk Setup
My Computer Desk Setup

My main keyboard and mouse is plugged into my work laptop.  Using Synergy, I can swipe my mouse from my work laptop screen to my desktop screen, and then use the mouse and keyboard on my desktop (as if they were plugged into the USB ports on my desktop).  I can also send the mouse all the way over to my personal laptop and control that with the mouse and keyboard plugged into my work laptop (whatever screen the mouse is currently on, is the one that the mouse and keyboard input will be sent to).

On my desktop, which has a newly installed Fedora 20 system, I wanted a way to start the Synergy client (synergyc) automatically so once the computer starts I can use the mouse and keyboard attached to my work laptop to control my Fedora system.  I found a simple way by created the file “~/.config/autostart/synergyc.desktop” and adding the appropriate values in there.  This worked, however if the synergyc client crashed for whatever reason, it would not automatically restart itself (it wasn’t a service after all, just an auto-start script).  I also found that I could create a systemd service to start on boot, but I had a couple of issues with this method as well:

  1. That service would be running as root, which could potentially be a security concern.
  2. Once I logged in to my Fedora system, if the synergyc service crashed for whatever reason, then it would not be able to restart itself .  Long story short (and perhaps not 100% technically correct), at that point the root user did not have access to the X display since control of it was given to my logged in user.  So if I started synergyc process at this point as my regular user, it would work just fine.

As I looked further into systemd, I learned about systemd user instances.  These are instances of systemd run as a user (with a specific user’s permissions) and it allows said user to start/stop/restart/check status of their own services that they want running (usually only started when that user logs on).  This looked promising as it would allow me to run synergyc as a service using my user’s permissions, taking away the security issue presented by running the service as root.  Unfortunately systemd user instances also proved to be troublesome.

After a lot of testing, troubleshooting, and finally getting my head wrapped around the concept of systemd user instances, I found that the user instance is started too late to allow my user’s synergyc service to be used for log in (issue 1 I wanted resolve), and started too early after logging in to allow my synergyc service to start successfully (my user did not have control of X display).  I could have added a restart delay timer in my systemd user service version of the synergyc service, but I found a different way that I thought was more promising — use a combination of systemd system services (normal systemd services), systemd user instance services, and desktop auto-start files (~/.config/autostart/*.desktop).

DIRECTIONS

The following directions were verified to work on my Fedora 20 64-bit system.  Hopefully your experience will be the same, though your mileage may vary.  I cannot guarantee exactly what will happen with your system, and I take no responsibility for any issues this causes.  Follow these at your own risk.

If you do not understand what a certain command or component might be doing, then I suggest you research it to fully understand what changes you are making to your system.

Install and Configure Synergy

If you don’t have it already, you’re going to need to download and install Synergy.

  1. Download — Go to http://synergy-project.org/download/?list and grab the appropriate file for your version of Linux.  In my case with Fedora 20 64-bit, http://synergy-project.org/download/?file=synergy-1.4.15-Linux-x86_64.rpm.  Or via command line:
    $ wget http://synergy-foss.org/download/?file=synergy-1.4.15-Linux-x86_64.rpm
  2. Install — Go to where you downloaded the file, and install it.
    $ cd ~/Downloads/
    $ sudo yum -y localinstall synergy-1.4.15-Linux-x86_64.rpm
  3. Get a working configuration — Open Synergy (in command line type: synergy) and edit your settings to successfully connect to your Synergy server running on another computer.  Verify you can connect to your server successfully.
  4. Copy the command used by synergyc to run and connect to your server — Run the following command and look for the line that starts with /usr/bin/synergyc:
    $ ps -eo command | grep -v grep | grep synergyc

    Note: The line should look something like
    /usr/bin/synergyc -d INFO -n YourHostName YourServerName:24800
    Note: If you use synergy’s built-in encryption then the option –crypto-pass <yourPasswordHash> will also be present. Example:
    /usr/bin/synergyc -d INFO -n pcName –crypto-pass passwordHashHere ServerName:24800

  5. Now stop synergy and close it.

Create systemd Service for synergyc

Creating this service will cause the synergyc service to start when the system boots, and will allow you to use the mouse and keyboard from your synergy server to enter the username and password to log into your system.

  1. Using your favorite text editor, create the file /lib/systemd/system/synergyc.service.
  2. Copy and paste the following config into the file.  In the ExecStart= line, put the entire command you found above, and make sure to add the “-f” option after /usr/bin/synergyc (as shown in the config below).  If you would like to have synergyc log to a specific file (instead of only using the default journald log), add this option after the -d option, -l /path/to/log-file/writeable/by/your/user.
    [Unit]
    Description=Synergy client service
    After=display-manager.service
    
    [Service]
    ExecStart=/usr/bin/synergyc -f -d INFO -n pcName --crypto-pass passwordHashHere ServerName:24800
    Restart=on-failure
    
    [Install]
    WantedBy=graphical.target
  3. Save your file.
  4. Give the file the appropriate permissions and ownership
    $ sudo chown root:root /lib/systemd/system/synergyc.service
    $ sudo chmod 0644 /lib/systemd/system/synergyc.service
  5. Have systemd add this service to its known list
     $ sudo systemctl daemon-reload
  6. Make sure it starts correctly:
     $ sudo systemctl start synergyc.service
  7. Make sure you can restart it:
     $ sudo systemctl restart synergyc.service
  8. Make sure you can stop it:
     $ sudo systemctl stop synergyc.service
  9. Make it load on boot
     $ sudo systemctl enable synergyc.service

Make System Kill Initial synergyc Process Upon Login

We need to kill this initial synergyc process since we don’t want to create a duplicate synergyc process, it was started as root, and it will not auto-restart itself if it crashes.

  1. Use your favorite text editor to edit the file /etc/gdm/PreSession/Default
    At bottom of file, add:

    # Need this line to kill the synergyc process started at boot
    killall synergyc

  2. Save the file

Verify systemd User Instance Starts on Boot

We just need to check that your systemd user instance is starting on boot.  This should be the default action of your system.

  1. Find your userid — At the command line type the following command, and look for “uid=####(username)”, where #### is any number, most likely 1000 (doesn’t have to be 1000, whatever is there is your userid).
    $ id
  2. Make sure a sytemd user instance has been created for your user
    $ sudo systemctl status user@####.service

    Verify systemd User Instance Running
    Verifying Your User Instance is Running

Create User Instance synergyc.service File

Now we need to create the synergyc.service file to use for our systemd user instance.

  1. Create appropriate directory
     $ mkdir -p ~/.config/systemd/user
  2. Copy systemd system synergyc.service file to our new directory
     $ cp /lib/systemd/system/synergyc.service ~/.config/systemd/user/
  3. In the new file, ~/.config/systemd/user/synergyc.service , change the line, WantedBy=graphical.target , to be, WantedBy=default.target
  4. Make your user instance aware of the service, and verify you can start, restart, and stop it:
    $ systemctl --user daemon-reload
    $ systemctl --user start synergyc.service
    $ systemctl --user restart synergyc.service
    $ systemctl --user stop synergyc.service

Create synergyc.desktop Autostart File

Now we need to create our synergyc.desktop file, which will run once we log in to our system.

  1. Create the file ~/.config/autostart/synergyc.desktop
  2. Copy and paste the config below into the file, then save your file.
    [Desktop Entry]
    Name=Synergyc
    GenericName=Software KVM
    Comment=Share your keyboard and mouse over a network
    Exec=systemctl --user start synergyc.service
    Terminal=false
    Type=Application
    Icon=/usr/share/icons/synergy.ico
    Categories=Utility
    StartupNotify=true
    X-GNOME-Autostart-enabled=true

Wrapping Up

You should now be able to reboot your system and control it from your Synergy server as soon as the graphical log in screen is displayed.  Please see the references below which helped me to create this guide.  If you have any questions or comments, leave them below!

References

How To: Configure Linux Client (Fedora 20) to Use Printer on Windows Server 2008 R2 Print Server

TABLE OF CONTENTS:

  1. BACKGROUND
  2. DIRECTIONS
    1. Basic Linux Client Configuration
    2. Configure Linux Client to Use LPD Protocol
    3. Configure Linux Client to Use IPP
  3. Printing a Test Page
  4. Wrapping Up

BACKGROUND:

This is the second post in this two post series, with the first covering how to configure the Windows Server 2008 R2 print server.  I will go over how to configure a Fedora 20 client, however most of what I do is applicable to other Linux distributions.  The printer I am using is a Canon Pixma MP620 with a share name, but you can use any printer that has Linux drivers available for it (can be configured by checking the manufacturers website, or following part of this guide).

As mentioned in the previous post, if you use IPP your credentials used to authenticate to the server will be stored in a text file on your Linux system.  There is a way to configure the Linux client so they are not stored there, however, if you choose this method then you will not be able to send test print jobs to the printer and you will not be able to print from the command line (ex: lp myFile.doc).  Also note that most if not all GUI programs will prompt you for credentials when you try to print; if you do not have the credentials saved then you must type in the correct credentials each time whereas if you had them saved then you could supply empty credentials and it will still print.

DIRECTIONS:

  • Note: Anywhere it says “serverName”, you should put either the DNS name of your server (ex: myPrintServer), or the IP address of the server (ex: 192.168.1.50)
  • Note: The share name I created for my printer is CanonMP620, whenever you see that name below, you should replace you configuration with the share name of your printer.

Basic Linux Client Configuration

  1. Verify the Cups service is installed and running
    • (on Fedora 20) $ sudo systemctl status cups.service

      Cups Status Output
      output of: sudo systemctl status cups.service
    • (on most other distributions and versions) $ sudo service cups status OR sudo service cupsd status
    • (alternatively) $ /etc/init.d/cups status OR /etc/init.d/cupsd status
  2. If you get a message saying it is stopped, then start the service
    • (on Fedora 20) $ sudo systemctl start cups.service
    • (on most other distributions and versions) $ sudo service cups start OR sudo service cupsd start
    • (alternatively) $ /etc/init.d/cups start OR /etc/init.d/cupsd start
  3. If you get a message saying the service is not found, then install cups:
    • (Fedora and most rpm based distros) $ sudo yum install cups
    • (OpenSuse) $ sudo zypper install cups
    • (Most Debian based distros) $ sudo apt-get install cups
  4. Verify that it is now running by performing step 1 above

Configure Linux Client to Use LPD Protocol

If you choose to use the LPD protocol (it is older than IPP but still works pretty well), then follow this portion of the guide, otherwise skip down to the “Configure Linux Client to Use IPP” section.

  1. Open a web browser (ex: Firefox) on your Linux client and go to http://localhost:631
  2. Click Administration
  3. Click Add Printer (If prompted for username and password, you can use “root” for username and the root user’s password)
  4. Select LPD/LPR Host or Printer, click Continue

    Selecting LPD Printer
    Selecting LPD/LPR Printer
  5. For “Connection” use lpd://serverName/PrinterShareName, then click Continue

    LPD Connection Name
    LPD Connection Name
  6. Fill in a name (required), and any other info (not necessary). Do not check “Share This Printer”, it is not necessary since it is already being shared from your print server (sharing it here would make it available so other computers could use your Linux client as a print server).
  7. Click Continue
  8. Either search for your printer driver based on the Make and Model list (select your Make, ex: Canon, click Continue, then select your model), or provide a PPD file (Linux printer driver file).
  9. Click Add Printer
  10. Edit preferences to your default liking, then click “Set Default Options”
  11. To verify printing works, go to the “Printing a Test Page” section

Configure Linux Client to Use IPP

  1. Open a web browser (ex: Firefox) on your Linux client and go to http://localhost:631
  2. Click Administration
  3. Click Add Printer (If prompted for username and password, you can use “root” for username and the root user’s password)
  4. Select “Internet Printing Protocol (https)”

    Select IPP Printer
    Select IPP Printer
  5. (saving credentials to a file) For “Connection” use https://username:password@serverName/printers/PrinterShareName/.printer
    Note: There is a typo in the picture below, the value for “Connection” should say “.printer” at the end, not “.priter”

    IPP Connection Name
    IPP Connection Name
  6. (not saving credentials to a file) For “Connection” use https://serverName/printers/PrinterShareName/.printer
  7. Fill in a name (required), and any other info (not necessary). Do not check “Share This Printer”, it is not necessary since it is already being shared from your print server (sharing it here would make it available so other computers could use your Linux client as a print server).
  8. Click Continue
  9. Either search for your printer driver based on the Make and Model list (select your Make, ex: Canon, click Continue, then select your model), or provide a PPD file (Linux printer driver file).
  10. Click Add Printer
  11. Edit preferences to your default liking, then click “Set Default Options”
  12. To verify printing works, go to the “Printing a Test Page” section

Printing a Test Page

  1. In the CUPS administration web site, Click Printers
  2. Click on the name of your Printer
  3. Click on the drop down where it says “Maintenance” and then Click on “Print Test Page”
    Dropdown Option to Print Test Page

Wrapping Up

Hopefully your test page printed successfully and everything is good to go.  If you’re having issues, have any questions, or have a comment to add to the post then leave it below!