init-script-template
init-script-template copied to clipboard
Service won't start since pid file is found
OS: Ubuntu 22.04.1 LTS
I used the template to create a service for starting the docker daemon.
Starting the service:
$ sudo /etc/init.d/docker start
Starting docker
Querying status:
$ sudo /etc/init.d/docker status
Stopped
Surely enough, the docker daemon isn't running at this stage.
Checking the error log /var/log/docker.err I see
time="2023-05-05T12:31:24.062889666Z" level=info msg="Starting up"
failed to start daemon: pid file found, ensure docker is not running or delete /var/run/docker.pid
Deleting the docker.pid file and starting the service again yields the same result.
If I delete the line
echo $! > "$pid_file"
from the script, the service works as expected and the docker.pid is automatically created with the correct PID.
It appears that the System V init script isn't supposed to be writing the docker.pid file, but should be leaving that to init.