Browse Source

Auto start

Vova Tkach 6 years ago
parent
commit
342fe64d21
1 changed files with 33 additions and 1 deletions
  1. 33 1
      Makefile

+ 33 - 1
Makefile

@@ -1,12 +1,13 @@
 RELEASEURL:="https://github.com/vladimirok5959/bash-empty-daemon/releases/download/latest/daemon.zip"
 BINDIR:=/usr/local/bin
 LROTDIR:=/etc/logrotate.d
+INITD:=/etc/init.d
 INSTALLDIR:=/etc
 SINITED:="0"
 
 default: check info
 
-install: check dir-test download create-link create-logrotate show-done-msg
+install: check dir-test download create-link create-logrotate create-autostart show-done-msg
 
 check:
 	$(eval SINITED="1")
@@ -71,6 +72,37 @@ create-logrotate: check-manual-run check-if-name-set
 		echo "}" >> $(LROTDIR)/$(NAME); \
 	fi
 
+create-autostart:
+	@if [ ! -z "$(NAME)" ]; then \
+		echo "Create auto start script..."
+		if [ ! -d "$(INITD)" ]; then \
+			echo "Aborted. Dir '$(INITD)' is not exists"; \
+			exit 1; \
+		fi
+		echo "#!/bin/sh" > $(INITD)/$(NAME); \
+		echo "" >> $(INITD)/$(NAME); \
+		echo "### BEGIN INIT INFO" >> $(INITD)/$(NAME); \
+		echo "# Provides:			nginx" >> $(INITD)/$(NAME); \
+		echo "# Required-Start:		\$local_fs \$network \$syslog" >> $(INITD)/$(NAME); \
+		echo "# Required-Stop:		\$local_fs \$network \$syslog" >> $(INITD)/$(NAME); \
+		echo "# Default-Start:		2 3 4 5" >> $(INITD)/$(NAME); \
+		echo "# Default-Stop:		0 1 6" >> $(INITD)/$(NAME); \
+		echo "# Short-Description:	starts the daemon ($(NAME))" >> $(INITD)/$(NAME); \
+		echo "# Description:		starts the daemon ($(NAME)) using start-stop-daemon" >> $(INITD)/$(NAME); \
+		echo "### END INIT INFO" >> $(INITD)/$(NAME); \
+		echo "" >> $(INITD)/$(NAME); \
+		echo "/usr/local/bin/$(NAME) \$1" >> $(INITD)/$(NAME); \
+		echo "exit 0" >> $(INITD)/$(NAME); \
+		chmod 0755 $(INITD)/$(NAME)
+		-ln -sf ../init.d/$(NAME) /etc/rc0.d/K01$(NAME); \
+		-ln -sf ../init.d/$(NAME) /etc/rc1.d/K01$(NAME); \
+		-ln -sf ../init.d/$(NAME) /etc/rc2.d/K01$(NAME); \
+		-ln -sf ../init.d/$(NAME) /etc/rc3.d/S01$(NAME); \
+		-ln -sf ../init.d/$(NAME) /etc/rc4.d/S01$(NAME); \
+		-ln -sf ../init.d/$(NAME) /etc/rc5.d/S01$(NAME); \
+		-ln -sf ../init.d/$(NAME) /etc/rc6.d/K01$(NAME); \
+	fi
+
 show-done-msg: check-manual-run
 	@echo "Done! Daemon with name '$(NAME)' successfully generated!"