0

Unlike the prior versions Ubuntu 15.04 now uses systemd instead of upstart. To start programs at boot I always created conf-files in /etc/init/. They would look like this:

start on login-session-start
script
/usr/bin/x11vnc -auth /var/run/lightdm/root/:0  -display :0  -rfbauth /etc/x11vnc.pass  -rfbport 5900  -noxrecord -noxfixes -noxdamage -forever -bg  -o /var/log/x11vnc.log
end script

Unfortunately, this does not work anymore in Ubuntu 15.04 and I was trying to find an equivalent to this conf-file that runs with systemd. Though the internet wasn't yet quite so resourceful.

What is necessary to start the above conf-file at boot? Are there translators between upstart and systemd?

2
  • Side note (sort of): Does it need to run as root, or can it be run as a user? Jun 15, 2015 at 23:23
  • Well, I wanna connect through vnc without being dependent on a certain user which is why I run it as root. Is that of any matter in relation to systemd?
    – Socrates
    Jun 15, 2015 at 23:30

1 Answer 1

4

If you want to, you can instead make a systemd .service file that does the same thing. A basic systemd .service file for the above command might look like the following:

[Unit]
Description=Start VNC server
Requires=lightdm.service
After=lightdm.service

[Service]
ExecStart=/usr/bin/x11vnc -auth /var/run/lightdm/root/:0  -display :0  -rfbauth /etc/x11vnc.pass  -rfbport 5900  -noxrecord -noxfixes -noxdamage -forever

[Install]
WantedBy=graphical.target

Things to note:

  • Because this service relies on lightdm starting up, I've added a Requires=lightdm.service. This means that if this service is requested to start, then lightdm.service will also be asked to start, but if lightdm.service fails to start, then this service won't be asked to start. Additionally, After=lightdm.service is needed so that this service will start after `lightdm.service has finished starting.
  • The command being run doesn't have -bg specified. In systemd, it's preferred that services stay in the foreground, so that systemd knows that they are running. Note that it is possible to specify a PID file for a service that goes into the background.
  • WantedBy=graphical.target specifies that, as part of starting up your GUI, this should also get started up.

To install this file so that the service is run as root, add this file into /etc/systemd/system. Then, run sudo systemctl enable <filename> (where <filename> is the name of the service file in /etc/systemd/system). A symlink should be created in /etc/systemd/system/graphical.target.wants/. After rebooting, when you run systemctl status <filename>, you should see that the service is recognized and not yet started.

Note that /etc/systemd/system/ is meant for system-wide services that the system administrator (you) add. /lib/systemd/system/ is meant for system-wide services installed by packages. You do not need to make a symlink to /lib/systemd/system/ for the service to load. The below table (taken from the systemd.unit manpage) describes what each location is for with regards to system services (there are separate paths for user services):

   ┌────────────────────┬─────────────────────────────┐
   │Path                │ Description                 │
   ├────────────────────┼─────────────────────────────┤
   │/etc/systemd/system │ Local configuration         │
   ├────────────────────┼─────────────────────────────┤
   │/run/systemd/system │ Runtime units               │
   ├────────────────────┼─────────────────────────────┤
   │/lib/systemd/system │ Units of installed packages │
   └────────────────────┴─────────────────────────────┘
11
  • Created file /lib/systemd/system/x11vnc.service with your above content, created link /etc/systemd/system/x11vnc.service -> /lib/systemd/system/x11vnc.service. But after booting the service does not run. systemctl status x11vnc.service leads to: Loaded: loaded (/lib/systemd/system/x11vnc.service; linked; vendor preset: enabled) and Active: inactive (dead)
    – Socrates
    Jun 16, 2015 at 1:01
  • @Socrates: What's the output of systemctl status graphical.target? Is there a symlink to your service in /lib/systemd/system/graphical.target.wants/? (Don't create one manually if it doesn't exist; it means something's wrong with the configuration.) Jun 16, 2015 at 2:06
  • systemctl status graphical.target: Loaded: loaded (/lib/systemd/system/graphical.target; static; vendor preset: enabled) and Active: active since Di 2015-06-16 04:08:01 CEST; 2min 39s ago. The only link in /lib/systemd/system/graphical.target.wants is systemd-update-utmp-runlevel.service -> ../systemd-update-utmp-runlevel.service.
    – Socrates
    Jun 16, 2015 at 2:15
  • @Socrates: See my updated answer. Jun 16, 2015 at 2:29
  • Ok, moved the file x11vnc.service to /etc/systemd/system and ran sudo systemctl enable x11vnc.service.
    – Socrates
    Jun 16, 2015 at 2:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .