[Unit] After=NetworkManager.service time-sync.target [Service] Type=forking User=spiri # Start roscore as a fork and then wait for the tcp port to be opened # —————————————————————- # Source all the environment variables, start roscore in a fork # Since the service type is forking, systemd doesn’t mark it as # ‘started’ until the original process exits, so we have the # non-forked shell wait until it can connect to the tcp opened by # roscore, and then exit, preventing conflicts with dependant services ExecStart=/bin/sh -c ". /opt/ros/melodic/setup.sh; . /etc/ros/env.sh; roscore & while ! echo exit | nc localhost 11311 > /dev/null; do sleep 1; done" [Install] WantedBy=multi-user.target