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:
- 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.
- I wanted synergyc to be run as a background service that would automatically restart itself if it crashed for whatever reason.
- I wanted synergyc to not be running as the root user whenever possible.
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:
- Wrapping Up
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 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:
- That service would be running as root, which could potentially be a security concern.
- 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).
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.
- 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
- 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
- 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.
- 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
- 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.
- Using your favorite text editor, create the file /lib/systemd/system/synergyc.service.
- 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
- Save your file.
- 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
- Have systemd add this service to its known list
$ sudo systemctl daemon-reload
- Make sure it starts correctly:
$ sudo systemctl start synergyc.service
- Make sure you can restart it:
$ sudo systemctl restart synergyc.service
- Make sure you can stop it:
$ sudo systemctl stop synergyc.service
- 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.
- 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
- 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.
- 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).
- Make sure a sytemd user instance has been created for your user
$ sudo systemctl status user@####.service
Create User Instance synergyc.service File
Now we need to create the synergyc.service file to use for our systemd user instance.
- Create appropriate directory
$ mkdir -p ~/.config/systemd/user
- Copy systemd system synergyc.service file to our new directory
$ cp /lib/systemd/system/synergyc.service ~/.config/systemd/user/
- In the new file, ~/.config/systemd/user/synergyc.service , change the line,
WantedBy=graphical.target, to be, WantedBy=default.target
- 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.
- Create the file ~/.config/autostart/synergyc.desktop
- 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
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!