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 SAF Beat and SAF Beat Manager.
Installing SAF Beat and SAF Beat Manager
- Preparing the Environment
Create system users (SAFBeat and sbm) and directories for the executable files (/app/SAFBeat and /app/SAFBeatManager).
Copy the .elf files of SAF Beat and SAF Beat Manager to the appropriate directories and make them executable:
chmod +x /app/SAFBeat/smartbeat.elf
chmod +x /app/SAFBeatManager/sbm.elf
- Initial Launch
Run the applications with root privileges for initial initialization:
/app/SAFBeat/smartbeat.elf install --ignore-systemd
/app/SAFBeatManager/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/SAFBeat/
chown -Rf sbm:sbm /app/SAFBeatManager/
Creating init.d Services
In systems without systemd support, service processes are managed via init.d scripts. Below are working init.d scripts for SAF Beat and SAF Beat Manager.
Script for SAF Beat
Service for smartBeat:
### BEGIN INIT INFO
# Provides: SAFBeat
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: SAF Beat Service
# Description: Service to run the SAF Beat application
### END INIT INFO
NAME="SAFBeat"
DESC="Smart beat Service"
DAEMON="/app/SAFBeat/smartbeat.elf"
DAEMON_OPTS="run"
PIDFILE="/var/run/$NAME.pid"
USER="SAFBeat"
WORKDIR="/app/SAFBeat"
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 SAF Beat Manager
Service for SAFBeatManager:
### BEGIN INIT INFO
# Provides: SAFBeatManager
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: SAF Beat Manager Service
# Description: Service to run the SAF Beat Manager application
### END INIT INFO
NAME="sbm"
DESC="SAF Beat Manager Service"
DAEMON="/app/SAFBeatManager/sbm.elf"
DAEMON_OPTS="run"
PIDFILE="/var/run/$NAME.pid"
USER="sbm"
WORKDIR="/app/SAFBeatManager"
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 saf-beat.service start
# The following commands are also available:
# service saf-beat.service stop
# service saf-beat.service status
# service saf-beat.service restart
Similarly - for SAFBeatManager.service.