New main PID does not belong to service, and PID file is not owned by root
Mia Lopez
When running vncserver (tightvncserver) on Xubuntu 18.04 as a service, I get this error
New main PID 2095 does not belong to service, and PID file is not owned by root. Refusing.
My service file looks like this
/etc/systemd/system/vncserver@.service
[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target
[Service]
Type=forking
User=user
PAMName=login
PIDFile=/home/user/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.targetAccording to this bug report, it has something to do with this change in systemd.
Any suggestions on updating my service file so it works with systemd again?
02 Answers
You're probably referencing the 16.04 version of this Digital Ocean VNC guide rather than the 18.04 version. In the 18.04 version the /etc/systemd/system/vncserver@.service file should look like this:
[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target
[Service]
Type=forking
User=sammy
Group=sammy
WorkingDirectory=/home/sammy
PIDFile=/home/sammy/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.targetRemember to replace all 4 instances of sammy with your own user name. The 18.04 version fixed my issues with the same PID file is not owned by root errors that you reported.
Commenting out PAMName=login solved the issue on 16.04