Article 5P20N Handling daemons in the init scripts

Handling daemons in the init scripts

by
gustav3000
from LinuxQuestions.org on (#5P20N)
Hi! I'm trying to write an init script running lxd-agent daemon. This daemon doesn't have options like -d or --daemon. What's the correct way to handle this daemon? Should I background this program manually in the init bash script using &? What about the PID file? In which package is start-stop-daemon on Slackware? Do I need to build it from SBo?

Here's my /etc/rc.d/rc.lxd-agent script:
Code:#!/bin/sh

PRGNAM="lxd-agent"
BIN="/run/lxd_config/drive/lxd-agent"
PID="/run/lxd-agent.pid"
REQUIRED_DIRS="/run/lxd_config/drive"

lxd_agent_start() {
if [ -s ${PID} ]; then
echo "${PRGNAM} is already running: $(cat ${PIS})"
exit 1
fi

if [ -x ${BIN} ]; then
echo "Starting ${PRGNAM}: ${BIN}"
mkdir -p ${REQUIRED_DIRS}
cd ${REQUIRED_DIRS} && ${BIN} &
echo $! > ${PID}
fi
}

lxd_agent_stop() {
if [ -s ${PID} ]; then
echo "Stopping ${PRGNAM}..."
kill -QUIT $(cat ${PID})
else
echo "${PRGNAM} is already stopped. Exiting..."
exit 1
fi
}

lxd_agent_restart() {
lxd_agent_stop
sleep 5
lxd_agent_start
}

lxd_agent_status() {
if [ -s ${PID} ]; then
echo "${PRGNAM} is running: $(cat ${PID})"
else
echo "${PRGNAM} does not seem to be running"
fi
}

case $1 in
"start")
lxd_agent_start
;;
"stop")
lxd_agent_stop
;;
"restart")
lxd_agent_restart
;;
"status")
lxd_agent_status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
;;
esaclatest?d=yIl2AUoC8zA latest?i=VpAwijowFJY:5z5A1V6rxxU:F7zBnMy latest?i=VpAwijowFJY:5z5A1V6rxxU:V_sGLiP latest?d=qj6IDK7rITs latest?i=VpAwijowFJY:5z5A1V6rxxU:gIN9vFwVpAwijowFJY
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments