I run a Linux system which makes use of both, SysVinit and systemd.
In order to set a dependency between each other (one should only start at boot after the other) I changed the SysVinit script to a systemd service.
1. Old situation:
openhab2 systemd service: /etc/systemd/system/multi-user.target.wants/openhab2.service
mosquitto SysVinit script: /etc/init.d/mosquitto
2. Disable the SysVinit script autostart (here mosquitto) by running as root:
update-rc.d mosquitto remove
> It will remove any link in /etc/rc*runlevel*.d to /etc/init.d./mosquitto
3. Delete the init script:
> This is importat as systemd checks the init scripts on every boot and then generates systemd services on the fly. Unfortunately these generated services cannot always be used as normal services.
As mentioned above, you will reboot to a clean system with no automatically generated systemd service.
3. Use your favorite text editor and create the new systemd service file:
Several ways are possible, I decided for:
4. Add content:
[Unit] Description=Mosquitto MQTT Broker daemon Documentation=man:mosquitto(8) Documentation=man:mosquitto.conf(5) ConditionPathExists=/etc/mosquitto/mosquitto.conf Wants=network-online.target After=network-online.target [Service] Type=simple ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d ExecReload=/bin/kill -HUP $MAINPID PIDFile=/run/mosquitto.pid Restart=on-failure [Install] WantedBy=multi-user.target
> Make sure the files marked in red are in place!
5. Enable systemd service:
systemctl enable mosquitto.service
> This create symlink from /etc/systemd/system/multi-user.target.wants/mosquitto.service to /usr/lib/systemd/system/mosquitto.service
6. Optional: Start your new service and check if it runs
systemctl start mosquitto.service netstat -lnp | grep mosquitto