I have been unable to find out how this "code" below is created.
# sudo /etc/init.d/samba restart
[ ok ] Restarting nmbd (via systemctl): nmbd.service.
[ ok ] Restarting smbd (via systemctl): smbd.service.
Specifically after calling the command, this is shown at first:
[ .. ] Restarting nmbd (via systemctl): nmbd.service.
Followed by a comfirmation of restart by the service, it changes to
[ ok ] Restarting nmbd (via systemctl): nmbd.service.
with the ..
changing to ok
I would like to incorporate these into my own scripts but haven't been able to find the code for these or any similar.
Help would be appreciated!
Please note, I am only using Samba as an example since this presents the output I am referring too.
The only possibility, to my knowledge, is that it runs some for of python script, but going through the service file for any arbitary service that has a similar output has no mention of a python script nor something that echo's ok
cat /etc/init.d/samba
#!/bin/sh
### BEGIN INIT INFO
# Provides: samba
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: ensure Samba daemons are started (nmbd, smbd and samba)
# Description: Starts Samba, a Windows AD and SMB/CIFS fileserver for UNIX
### END INIT INFO
set -e
# start nmbd, smbd and samba-ad-dc unconditionally
# the init scripts themselves check if they are needed or not
case $1 in
start)
/etc/init.d/nmbd start
/etc/init.d/smbd start
/etc/init.d/samba-ad-dc start
;;
stop)
/etc/init.d/samba-ad-dc stop
/etc/init.d/smbd stop
/etc/init.d/nmbd stop
;;
reload)
/etc/init.d/smbd reload
;;
restart|force-reload)
/etc/init.d/nmbd "$1"
/etc/init.d/smbd "$1"
/etc/init.d/samba-ad-dc "$1"
;;
status)
status=0
NMBD_DISABLED=`testparm -s --parameter-name='disable netbios' 2>/dev/null || true`
SERVER_ROLE=`samba-tool testparm --parameter-name="server role" 2>/dev/null | tail -1 || true`
if [ "$SERVER_ROLE" != "active directory domain controller" ]; then
if [ "$NMBD_DISABLED" != "Yes" ]; then
/etc/init.d/nmbd status || status=$?
fi
/etc/init.d/smbd status || status=$?
else
/etc/init.d/samba-ad-dc status || status=$?
fi
exit $status
;;
*)
echo "Usage: /etc/init.d/samba {start|stop|reload|restart|force-reload|status}"
exit 1
;;
esac
apt-get
since I've never read their source code. They might be doing something far more complex. The benefit of this approach is that it's simple and easy to understand. – Sergiy Kolodyazhnyy Sep 16 '16 at 07:22