2

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?

mark
  • 691
  • 2
  • 14
  • 31

3 Answers3

6

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.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
0

Ubuntu 21.04, minikube installed via deb: also need to set the systemd unit working directory to match minikube run off the cmdline:

[Unit]
Description=minikube

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/root
ExecStart=/usr/bin/minikube start --embed-certs --driver=none
ExecStop=/usr/bin/minikube stop

[Install]
WantedBy=multi-user.target

Unit can be created with systemctl edit --force --full minikube.service

# systemctl status minikube
● minikube.service - minikube
     Loaded: loaded (/etc/systemd/system/minikube.service; enabled; vendor preset: enabled)
     Active: active (exited) since Fri 2021-06-25 03:01:57 UTC; 4s ago
    Process: 418 ExecStart=/usr/bin/minikube start --embed-certs --driver=none (code=exited, status=0/SUCCESS)
   Main PID: 418 (code=exited, status=0/SUCCESS)

...
Jun 25 03:01:57 minikube systemd[1]: Finished minikube.
# minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

~root/.kube/config includes embedded certs and can be used off host/vm.

0

work for me on centos 8 and 7

create the file location /usr/lib/systemd/system/minikube.service

[Unit]
Description=minikube
After=network-online.target firewalld.service containerd.service docker.service
Wants=network-online.target docker.service
Requires=docker.socket containerd.service docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/root
ExecStart=/usr/local/bin/minikube start --driver=none
ExecStop=/usr/local/bin/minikube stop
User=root
Group=root

[Install]
WantedBy=multi-user.target

run the next commands to enable and start the service

systemctl daemon-reload 
systemctl enable minikube
systemctl start minikube