Ignored days are Init.d, wtf are you still reading this? There is no more sudo service
, all new children are floating down syscrtl
Currently, for example, on my ubuntu 17.04 production server, /etc/rc.local
does not even exist
Just write a new one!
rc.local
is amazing, especially when combined with the unix demonize program style ... these two, I can pretty much call it a day.
However, if you want to take rc.local
to the next level, I will talk about the basic ideas of my own personal redis init.d script - the same one that we use on production servers in my company:
pre-empt redis complaint about system sockets / file limits
slap on some linux perf and mess with sysconf in constant mode
autopilot redis while i go nap
next if we do it right:
let them have good idiomatic cases of $ money numbers, oriented to start and stop without sorting through excessive tracking PID shenanigans
use the start-stop daemon (i.e. the death of the parent process cannot be interrupted if there is no parent process)
case $1 in start) if [ ! -f $PIDFILE ]; then echo -n "Starting $NAME: " start-stop-daemon --start --pidfile $PIDFILE --exec $EXEC -- $CONF echo "waiting for redis db to start..." while [ ! -f $PIDFILE ]; do sleep 0.1; done fi PID=$(cat $PIDFILE) echo "running with pid: $PID" ;; stop) if [ ! -f $PIDFILE ]; then echo "redis is already stopped" else PID=$(cat $PIDFILE) echo -n "Stopping $NAME: " $CLIEXEC -s $SOCKET shutdown echo "waiting for shutdown..." while [ -x /proc/${PID} ]; do sleep 0.1 done echo "db stopped." fi ;; status) if [ -f $PIDFILE ]; then PID=$(cat $PIDFILE) echo "running with pid: $PID" else echo "stopped." fi ;; restart|force-reload) $0 stop && $0 start ;; *) echo "Argument \"$1\" not implemented." exit 2 ;; esac exit 0
- modify
redis.conf
to indicate daemonize yes
. Make redis the main responsible party for the administrative state of the PID file (in case you are wondering why we did not need to do anything with it in the script, except for reading from it, if any)
mkdir /etc/redis echo 'daemonize yes' >> /etc/redis/redis.conf echo 'pidfile /var/run/redis.pid' >> /etc/redis/redis.conf
- update rc record by name after copying and setting executable bits:
mkdir /etc/redis vim /etc/redis/redis
- Here is a complete example of a link with a service installer. Again, be sure to edit
conf
and install
for you. Most people will probably want to remove the listening file path in favor of the TCP stack w / redis the port number open to clients (s),
source share