5

I am on Linux Mint 19.3 and would like to make the TeamViewer systemd service only run when I launch the GUI app (/opt/teamviewer/tv_bin/script/teamviewer). On Windows, this is fairly easy to do from the Services dialog by selecting the TeamViewer and changing its "Startup Type" from "Automatic" to "Manual".

In Linux, I have TeamViewer 15 (installed via deb file from official site). I am seeing that the systemd service file has:

$ cat /etc/systemd/system/teamviewerd.service
[Unit]
Description = TeamViewer remote control daemon
After = network.target network-online.target dbus.service
Wants = network-online.target
Requires = dbus.service

[Service]
Type = forking
PIDFile = /var/run/teamviewerd.pid
ExecStart = /opt/teamviewer/tv_bin/teamviewerd -d
Restart = on-abort
StartLimitInterval = 60
StartLimitBurst = 10

[Install]
WantedBy = multi-user.target

and the service autostarts during login which I don't want. I don't mind hacking out a new bash script to start the service just before launching the gui but I'm not great with editing systemd services and had a concern about new versions overwriting my changes.

Questions:

  1. I could probably just remove the service file and use a bash wrapper script just before/after the gui process starts/ends vs just launching its 'ExecStart' args directly. BUT... seems like this could be bad if the gui process were to interface with the service process using systemd calls... If I were going to keep the systemd service file around for better compat, is there a way to configure the service file to still have the service enabled but NOT to run on startup but still allow it to be manually controlled via sudo systemctl [start|stop] teamviewerd ?

  2. Is there a way in apt to specify a post-install script for a particular package. (e.g. when apt etc installs a new version of teamviewer which presumably reinstalls the systemd service and *.desktop files, I would like to have it automatically run a script to "fix" those things). I saw this and this and get that I would need something like /etc/apt/apt.conf.d/custom-hooks with a path to a script but not seeing how to: a) pass a list of last installed packages or b) find out which packages were just installed by apt. Is there a more elegant way to do things than capturing a list in the PRE hook and then recapturing and checking for changes in the POST hook?

  3. Is there a more elegant approach that I have not considered?

zpangwin
  • 591
  • 1
  • 4
  • 20
  • 1
    Edit: [this](https://stackoverflow.com/questions/42901598/how-do-i-create-a-systemd-service-that-doesnt-start-on-reboot) might be what I need for the first question. Don't have time to test it at the moment but if it checks out, I'll update strike-through that question. – zpangwin Sep 02 '20 at 21:37

1 Answers1

2

Usually, the startup of installed daemons is controlled via systemctl [enable|disable] <service_name>. Note, that you can still start your disabled service manually with systemctl start <service_name>.

But with Teamviewer it's different. Every time Teamviewer is updated, it overwrites the /etc/systemd/system/teamviewerd.service file and enables its service for startup. So the daemon will work even if you don't want to.
I solve this issue by adding overrides to the service:

systemctl stop teamviewerd.service
mkdir -p /etc/systemd/system/teamviewerd.service.d
cat >/etc/systemd/system/teamviewerd.service.d/override.conf <<EOF
[Unit]
ConditionPathExists=/tmp/allow_teamviewerd
EOF
systemctl daemon-reload

Now, to start the daemon run the following:

touch /tmp/allow_teamviewerd
systemctl start teamviewerd.service
rm /tmp/allow_teamviewerd

And stop as usual:

systemctl stop teamviewerd.service
SergA
  • 186
  • 4
  • Thanks! definitely handles it better than my current workaround (just had the enable/disable part mapped to aliases tv_on and tv_off respectively). Would still like to see if systemd supports starting a service when some predefined process is launched / on-demand (similar to "Manual' Windows services). The main thing this would allow is to have TV service as not running most of the time while also allowing non-sudo users to start it up if they launch the app/need help (I have LM on my mom's pc as well). There's probably other ways to achieve this though like possibly via bash scripts + polkit – zpangwin Mar 28 '21 at 06:06