これは、なにをしたくて書いたもの?
以前、TigerVNCをUbuntu Linux 24.04 LTSにインストールしました。
Ubuntu Linux 24.04 LTSにVNCサーバーをインストールする - CLOVER🍀
systemdのユニットとして登録する方法を確認しておこう、ということで。
環境
今回の環境はこちら。
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 24.04.3 LTS Release: 24.04 Codename: noble $ uname -srvmpio Linux 6.8.0-88-generic #89-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 01:02:46 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
VNCサーバーはTigerVNCです。
$ vncserver -version Xvnc TigerVNC 1.13.1 - built 2024-04-01 08:26 Copyright (C) 1999-2022 TigerVNC Team and many others (see README.rst) See https://www.tigervnc.org for information on TigerVNC. Underlying X server release 12101011
VNCサーバーをsystemdのユニットとして登録します。
最初に1度起動して、VNCサーバーのパスワードは設定済みとします。またリモート接続を許可するものとします(-localhost no)。
$ vncserver -localhost no :1
パスワードを変更する場合はこちらですね。
$ vncpasswd
systemdのユニットとして登録します。
$ sudo systemctl edit --force --full vncserver@1
内容はこちら。
[Unit] Description=TigerVNC Server Service After=network-online.target Wants=network-online.target [Service] Type=forking User=[ユーザー名] Group=[グループ名] WorkingDirectory=/home/[ユーザー名] PIDFile=/home/[ユーザー名]/.vnc/%H:%i.pid ExecStart=/usr/bin/vncserver -localhost no :%i ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target
このあたりがポイントでしょうか。
PIDFile=/home/[ユーザー名]/.vnc/%H:%i.pid ExecStart=/usr/bin/vncserver -localhost no :%i ExecStop=/usr/bin/vncserver -kill :%i
あとはsystemctlで操作できます。
$ sudo systemctl start vncserver@1
自動起動を有効に。
$ sudo systemctl enable vncserver@1
こんなエラーが出る場合は
1月 03 00:11:56 llm-server gnome-session-binary[4404]: WARNING: Failed to upload environment to DBus: Failed to execute child process “dbus-launch” (No such file or directory) 1月 03 00:11:56 llm-server gnome-session[4404]: gnome-session-binary[4404]: WARNING: Failed to upload environment to systemd: Failed to execute child process “dbus-launch” (No such file or directory)
こちらをインストールしましょう。
$ sudo apt install dbus-x11