This is a go project, others can be consulted.
The first thing to do is to have a script like demo
#!/bin/bash## Etcd This shell script takes care of starting and stopping etcd## Chkconfig:2345 the -# # # BEGIN INIT info# provides:etcd# Required-Start: $network $syslog # Required-Stop: $network $syslog # Default-start:# Default-stop:# Short-Description:start and stop etcd### END INIT INFO # # Source function library.#./etc/rc.d/init.d/Functionsexport Java_home=/Usrexport PATH= $JAVA _home/Bin: $PATHGOPATH=/opt/etcdrepo/Etcdetcd_home=$GOPATHEtcd_pid () {echo ' PS aux| Grep"etcd\>"| Grep-v grep | Awk'{print $}'| Tail-n1'} start () {PID=$ (etcd_pid)if[-N"$pid"] then echo"Etcd is already running (PID: $pid)" Else#Start Etcd Echo"starting ETCD"Ulimit-N100000umask007sudo $ETCD _home/bin/etcd-data-dir machines/machine1-name Machine1 & >Log.txt fireturn 0} stop () {PID=$ (etcd_pid)if[-N"$pid"] then echo-n-e"\nkilling processes which didn ' t stop after $SHUTDOWN _wait seconds"Kill-9$pidElseEcho"Etcd is not running"fireturn 0} Case$1 inchstart) Start; stop) stop;; restart) stop start;; status) PID=$ (etcd_pid)if[-N"$pid"] then echo"Etcd is running with PID: $pid" ElseEcho"Etcd is not running"fi;; Esacexit0
2. Put this script under/ETC/INIT.D or/ETC/RC.D/INIT.D
3. Set permissions
sudo chmod 777 Demosudo chkconfig--add demosudo chkconfig--list Demosudo Service Demo start when the service is not found
4. Reboot Linux Try it!
Apply random boot on Linux