Configuring init.d service in the absence of systemd
In distributions where systemd is unavailable (e.g., older Linux versions like CentOS 6), service management is handled through init.d scripts. This article describes how to create and configure init.d-compatible services for running Smart Beat and Smart Beat Manager.
Installing Smart Beat and Smart Beat Manager
- Preparing the Environment
Create system users (smartbeat and sbm) and directories for the executable files (/app/smartBeat and /app/smartBeatManager).
Copy the .elf files of Smart Beat and Smart Beat Manager to the appropriate directories and make them executable:
chmod +x /app/smartBeat/smartbeat.elf
chmod +x /app/smartBeatManager/sbm.elf
- Initial Launch
Run the applications with root privileges for initial initialization:
/app/smartBeat/smartbeat.elf install --ignore-systemd
/app/smartBeatManager/sbm.elf install --ignore-systemd
This will create the necessary working folders and configuration files.
After generation, assign ownership of the directories to the respective users:
chown -Rf smartbeat:smartbeat /app/smartBeat/
chown -Rf sbm:sbm /app/smartBeatManager/
Creating init.d Services
In systems without systemd support, service processes are managed via init.d scripts. Below are working init.d scripts for Smart Beat and Smart Beat Manager.
Script for Smart Beat
Service for smartBeat:
### BEGIN INIT INFO
# Provides: smartbeat
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Smart Beat Service
# Description: Service to run the Smart Beat application
### END INIT INFO
NAME="smartbeat"
DESC="Smart beat Service"
DAEMON="/app/smartBeat/smartbeat.elf"
DAEMON_OPTS="run"
PIDFILE="/var/run/$NAME.pid"
USER="smartbeat"
WORKDIR="/app/smartBeat"
test -x $DAEMON || exit 0
case "$1" in
start)
echo "Starting $DESC..."
su -c "cd $WORKDIR && nohup $DAEMON $DAEMON_OPTS > /dev/null 2>&1 &" $USER
echo "$DESC started."
;;
stop)
echo "Stopping $DESC..."
pkill -f "$DAEMON $DAEMON_OPTS"
echo "$DESC stopped."
;;
restart)
echo "Restarting $DESC..."
$0 stop
sleep 10
$0 start
;;
status)
if pgrep -f "$DAEMON $DAEMON_OPTS" > /dev/null; then
echo "$DESC is running."
else
echo "$DESC is not running."
fi
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}"
exit 1
;;
esac
exit 0
Script for Smart Beat Manager
Service for smartBeatManager:
### BEGIN INIT INFO
# Provides: smartbeatmanager
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Smart Beat Manager Service
# Description: Service to run the Smart Beat Manager application
### END INIT INFO
NAME="sbm"
DESC="Smart Beat Manager Service"
DAEMON="/app/smartBeatManager/sbm.elf"
DAEMON_OPTS="run"
PIDFILE="/var/run/$NAME.pid"
USER="sbm"
WORKDIR="/app/smartBeatManager"
test -x $DAEMON || exit 0
case "$1" in
start)
echo "Starting $DESC..."
su -c "cd $WORKDIR && nohup $DAEMON > /dev/null 2>&1 &" $USER
echo "$DESC started."
;;
stop)
echo "Stopping $DESC..."
pkill -f "$DAEMON"
echo "$DESC stopped."
;;
restart)
echo "Restarting $DESC..."
$0 stop
sleep 1
$0 start
;;
status)
if pgrep -f "$DAEMON" > /dev/null; then
echo "$DESC is running."
else
echo "$DESC is not running."
fi
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}"
exit 1
;;
esac
exit 0
Now services can be managed using standard commands:
service smartBeat.service start
# The following commands are also available:
# service smartBeat.service stop
# service smartBeat.service status
# service smartBeat.service restart
Similarly - for smartBeatManager.service.