大网数据广告活动
服务器运维问答

How to run minikube start as a linux service on startup?

· 52CE 我爱测

This question is related to How to arrange a non admin command as a systemd service? I have the following minikube.service file: [Unit] Description=Runs minikube on startup After=vboxautostart-service.service vboxballoonctrl-serv…

问题原文

原帖链接 · mark · CC BY-SA 4.0

This question is related to How to arrange a non admin command as a systemd service?

I have the following minikube.service file:

[Unit]
Description=Runs minikube on startup
After=vboxautostart-service.service vboxballoonctrl-service.service vboxdrv.service vboxweb-service.service

[Service]
Type=forking
ExecStart=/usr/local/bin/minikube start
User=mark
Group=mark

[Install]
WantedBy=multi-user.target

And it works fine when I start it manually from the shell:

mark@minikube-vm:~$ sudo systemctl start minikube.service
mark@minikube-vm:~$ minikube ip
192.168.99.100
mark@minikube-vm:~$ systemctl status minikube.service
● minikube.service - Runs minikube on startup
   Loaded: loaded (/etc/systemd/system/minikube.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2020-09-25 17:32:48 UTC; 34min ago
  Process: 8388 ExecStart=/usr/local/bin/minikube start (code=exited, status=0/SUCCESS)
    Tasks: 46 (limit: 19141)
   CGroup: /system.slice/minikube.service
           ├─8434 /usr/lib/virtualbox/VBoxXPCOMIPCD
           ├─8439 /usr/lib/virtualbox/VBoxSVC --auto-shutdown
           ├─8618 /usr/lib/virtualbox/VBoxHeadless --comment minikube --startvm 6ec91432-0f09-4fdc-9976-6f736b15c37f --vrde config
           ├─8632 /usr/lib/virtualbox/VBoxNetDHCP --comment HostInterfaceNetworking-vboxnet0 --config /tmp/dhcp-config-kiyf3.xml
           └─8658 /usr/bin/pulseaudio --start --log-target=syslog

Sep 25 17:31:22 minikube-vm minikube[8388]: * Using the virtualbox driver based on existing profile
Sep 25 17:31:22 minikube-vm minikube[8388]: * Starting control plane node minikube in cluster minikube
Sep 25 17:31:22 minikube-vm minikube[8388]: * Restarting existing virtualbox VM for "minikube" ...
Sep 25 17:31:23 minikube-vm pulseaudio[8658]: [pulseaudio] server-lookup.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSu
Sep 25 17:31:23 minikube-vm pulseaudio[8658]: [pulseaudio] main.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSupported:
Sep 25 17:32:16 minikube-vm minikube[8388]: * Preparing Kubernetes v1.19.0 on Docker 19.03.12 ...
Sep 25 17:32:43 minikube-vm minikube[8388]: * Verifying Kubernetes components...
Sep 25 17:32:48 minikube-vm minikube[8388]: * Enabled addons: dashboard, default-storageclass, storage-provisioner
Sep 25 17:32:48 minikube-vm minikube[8388]: * Done! kubectl is now configured to use "minikube" by default
Sep 25 17:32:48 minikube-vm systemd[1]: Started Runs minikube on startup.
mark@minikube-vm:~$

But on machine boot it fails:

mark@minikube-vm:~$ systemctl status minikube.service
● minikube.service - Runs minikube on startup
   Loaded: loaded (/etc/systemd/system/minikube.service; enabled; vendor preset: enabled)
   Active: failed (Result: timeout) since Fri 2020-09-25 17:18:09 UTC; 12min ago
  Process: 7140 ExecStart=/usr/local/bin/minikube start (code=killed, signal=TERM)

Sep 25 17:16:39 minikube-vm minikube[7140]: * Using the virtualbox driver based on existing profile
Sep 25 17:16:39 minikube-vm minikube[7140]: * Starting control plane node minikube in cluster minikube
Sep 25 17:16:39 minikube-vm minikube[7140]: * Restarting existing virtualbox VM for "minikube" ...
Sep 25 17:16:40 minikube-vm pulseaudio[7438]: [pulseaudio] server-lookup.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSu
Sep 25 17:16:40 minikube-vm pulseaudio[7438]: [pulseaudio] main.c: Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSupported:
Sep 25 17:17:34 minikube-vm minikube[7140]: * Preparing Kubernetes v1.19.0 on Docker 19.03.12 ...
Sep 25 17:18:06 minikube-vm minikube[7140]: * Verifying Kubernetes components...
Sep 25 17:18:08 minikube-vm systemd[1]: minikube.service: Start operation timed out. Terminating.
Sep 25 17:18:09 minikube-vm systemd[1]: minikube.service: Failed with result 'timeout'.
Sep 25 17:18:09 minikube-vm systemd[1]: Failed to start Runs minikube on startup.
mark@minikube-vm:~$

What am I missing?

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

You've started a "service" which is basically just a script that runs some commands and then exits. This sort of thing should use Type=oneshot and RemainAfterExit=yes in a systemd unit, so that systemd knows the process will go away but still consider the "service" active.

You should also add a matching ExecStop= line that stops minikube, for completeness.

The systemd documentation has another example of such a unit.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-09-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。