Jan Wagner revised this gist 10 years ago. Go to revision
1 file changed, 1 insertion, 1 deletion
node_debian_init.sh
| @@ -85,7 +85,7 @@ DAEMON=/usr/local/bin/$NAME # this SHOULD POINT TO where your no | |||
| 85 | 85 | [ $UID -eq "0" ] && LOCAL_VAR_RUN=/var/run # in case this script is run by root, override user setting | |
| 86 | 86 | THIS_ARG=$0 | |
| 87 | 87 | INIT_SCRIPT_NAME=`basename $THIS_ARG` | |
| 88 | - | [ -h $THIS_ARG ] && INIT_SCRIPT_NAME=`basename $(readlink $THIS_ARG)` # in case of symlink | |
| 88 | + | #[ -h $THIS_ARG ] && INIT_SCRIPT_NAME=`basename $(readlink $THIS_ARG)` # in case of symlink | |
| 89 | 89 | INIT_SCRIPT_NAME_NOEXT=${INIT_SCRIPT_NAME%.*} | |
| 90 | 90 | PIDFILE="$LOCAL_VAR_RUN/$INIT_SCRIPT_NAME_NOEXT.pid" | |
| 91 | 91 | SCRIPTNAME=/etc/init.d/$INIT_SCRIPT_NAME | |
Jan Wagner revised this gist 10 years ago. Go to revision
1 file changed, 1 insertion, 1 deletion
node_debian_init.sh
| @@ -107,7 +107,7 @@ SCRIPTNAME=/etc/init.d/$INIT_SCRIPT_NAME | |||
| 107 | 107 | . /lib/lsb/init-functions | |
| 108 | 108 | ||
| 109 | 109 | # uncomment to override system setting | |
| 110 | - | VERBOSE=yes | |
| 110 | + | #VERBOSE=yes | |
| 111 | 111 | ||
| 112 | 112 | # define this after reading default values | |
| 113 | 113 | NODECMD="exec $DAEMON $DAEMON_ARGS >>$LOCAL_VAR_LOGS 2>&1" # node comman | |
Jan Wagner revised this gist 10 years ago. Go to revision
1 file changed, 3 insertions, 1 deletion
node_debian_init.sh
| @@ -72,7 +72,6 @@ LOCAL_VAR_RUN=/usr/local/var/run # in case the init script is run by | |||
| 72 | 72 | ||
| 73 | 73 | NAME=node # name of the node.js executable | |
| 74 | 74 | DAEMON=/usr/local/bin/$NAME # this SHOULD POINT TO where your node executable is | |
| 75 | - | NODECMD="exec $DAEMON $DAEMON_ARGS >>$LOCAL_VAR_LOGS 2>&1" # node command | |
| 76 | 75 | # | |
| 77 | 76 | # # | |
| 78 | 77 | # END </MODIFY TO REFLECT YOUR SETTINGS> # | |
| @@ -110,6 +109,9 @@ SCRIPTNAME=/etc/init.d/$INIT_SCRIPT_NAME | |||
| 110 | 109 | # uncomment to override system setting | |
| 111 | 110 | VERBOSE=yes | |
| 112 | 111 | ||
| 112 | + | # define this after reading default values | |
| 113 | + | NODECMD="exec $DAEMON $DAEMON_ARGS >>$LOCAL_VAR_LOGS 2>&1" # node comman | |
| 114 | + | ||
| 113 | 115 | # | |
| 114 | 116 | # Function that starts the daemon/service | |
| 115 | 117 | # | |
Jan Wagner revised this gist 10 years ago. Go to revision
1 file changed, 3 insertions, 3 deletions
node_debian_init.sh
| @@ -91,15 +91,15 @@ INIT_SCRIPT_NAME_NOEXT=${INIT_SCRIPT_NAME%.*} | |||
| 91 | 91 | PIDFILE="$LOCAL_VAR_RUN/$INIT_SCRIPT_NAME_NOEXT.pid" | |
| 92 | 92 | SCRIPTNAME=/etc/init.d/$INIT_SCRIPT_NAME | |
| 93 | 93 | ||
| 94 | + | # Read configuration variable file if it is present | |
| 95 | + | [ -r /etc/default/$INIT_SCRIPT_NAME ] && . /etc/default/$INIT_SCRIPT_NAME | |
| 96 | + | ||
| 94 | 97 | # Exit if the package is not installed | |
| 95 | 98 | [ -x "$DAEMON" ] || { echo "can't find Node.js ($DAEMON)" >&2; exit 0; } | |
| 96 | 99 | ||
| 97 | 100 | # Exit if the 'run' folder is not present | |
| 98 | 101 | [ -d "$LOCAL_VAR_RUN" ] || { echo "Directory $LOCAL_VAR_RUN does not exist. Modify the '$INIT_SCRIPT_NAME_NOEXT' init.d script ($THIS_ARG) accordingly" >&2; exit 0; } | |
| 99 | 102 | ||
| 100 | - | # Read configuration variable file if it is present | |
| 101 | - | [ -r /etc/default/$INIT_SCRIPT_NAME ] && . /etc/default/$INIT_SCRIPT_NAME | |
| 102 | - | ||
| 103 | 103 | # Load the VERBOSE setting and other rcS variables | |
| 104 | 104 | . /lib/init/vars.sh | |
| 105 | 105 | ||
Jan Wagner revised this gist 10 years ago. Go to revision
No changes
Stefan Greiner revised this gist 12 years ago. Go to revision
1 file changed, 1 insertion, 1 deletion
node_debian_init.sh
| @@ -199,7 +199,7 @@ do_status() { | |||
| 199 | 199 | log_success_msg "$INIT_SCRIPT_NAME_NOEXT launched by $NODEUSER is not running, phantom pidfile $PIDFILE" | |
| 200 | 200 | exit 1 | |
| 201 | 201 | else | |
| 202 | - | log_success_msg "Not running. No instance of $INIT_SCRIPT_NAME_NOEXT launched $NODEUSER found" | |
| 202 | + | log_success_msg "Not running. No instance of $INIT_SCRIPT_NAME_NOEXT launched by $NODEUSER found" | |
| 203 | 203 | exit 3 | |
| 204 | 204 | fi | |
| 205 | 205 | fi | |
sgreiner revised this gist 12 years ago. Go to revision
1 file changed, 1 insertion, 1 deletion
node_debian_init.sh
| @@ -44,7 +44,7 @@ | |||
| 44 | 44 | # Place this file in /etc/init.d. | |
| 45 | 45 | ### END INIT INFO | |
| 46 | 46 | ||
| 47 | - | # Author: CADENAS GmbH <sysadmin@cadenas.de> | |
| 47 | + | # Author: My Name <myname@domain.tld> | |
| 48 | 48 | # | |
| 49 | 49 | # Please remove the "Author" lines above and replace them | |
| 50 | 50 | # with your own name if you copy and modify this script. | |
StefanGreiner revised this gist 12 years ago. Go to revision
1 file changed, 21 insertions, 24 deletions
node_debian_init.sh
| @@ -1,4 +1,4 @@ | |||
| 1 | - | #!/bin/sh | |
| 1 | + | #!/bin/bash | |
| 2 | 2 | # ------------------------------------------------------------------------------ | |
| 3 | 3 | # SOME INFOS : fairly standard (debian) init script. | |
| 4 | 4 | # Note that node doesn't create a PID file (hence --make-pidfile) | |
| @@ -31,6 +31,7 @@ | |||
| 31 | 31 | # | |
| 32 | 32 | # 5) based on : Debian /etc/init.d/skeleton | |
| 33 | 33 | # modified by : Peter Host (www.oghme.com) | |
| 34 | + | # modified by : Stefan Greiner (www.cadenas.de) | |
| 34 | 35 | # ______________________________________________________________________________ | |
| 35 | 36 | ### BEGIN INIT INFO | |
| 36 | 37 | # Provides: node_debian_init | |
| @@ -39,16 +40,11 @@ | |||
| 39 | 40 | # Default-Start: 2 3 4 5 | |
| 40 | 41 | # Default-Stop: 0 1 6 | |
| 41 | 42 | # Short-Description: DEBIAN initscript for node.js servers/apps | |
| 42 | - | # Description: ex : proxy server is a node.js http server listening on | |
| 43 | - | # port 8080 (relayed from 80 by iptables). It balances | |
| 44 | - | # http requests between the main nodejs server | |
| 45 | - | # (nodejs.mydomain.com:8000), the static file-server | |
| 46 | - | # (static.mydomain.com) and the legacy apache server | |
| 47 | - | # (apache.mydomain.com) and possibly other servers | |
| 48 | - | # place this file in /etc/init.d. | |
| 43 | + | # Description: DEBIAN initscript for node.js servers/apps | |
| 44 | + | # Place this file in /etc/init.d. | |
| 49 | 45 | ### END INIT INFO | |
| 50 | 46 | ||
| 51 | - | # Author: My Name <myname@domain.tld> | |
| 47 | + | # Author: CADENAS GmbH <sysadmin@cadenas.de> | |
| 52 | 48 | # | |
| 53 | 49 | # Please remove the "Author" lines above and replace them | |
| 54 | 50 | # with your own name if you copy and modify this script. | |
| @@ -57,12 +53,12 @@ | |||
| 57 | 53 | # PATH should only include /usr/* if it runs after the mountnfs.sh script | |
| 58 | 54 | PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin # modify if you need | |
| 59 | 55 | ||
| 60 | - | DAEMON_ARGS="/path/to/app.js" # path to your node.js server/app | |
| 56 | + | DAEMON_ARGS="/path/to/your/app.js" # path to your node.js server/app | |
| 61 | 57 | # NB: don't use ~/ in path | |
| 62 | 58 | ||
| 63 | - | DESC="node.js http server" # whatever fancy description you like | |
| 59 | + | DESC="Node.js server" # whatever fancy description you like | |
| 64 | 60 | ||
| 65 | - | NODEUSER=myuser:mygroup # USER who OWNS the daemon process (no matter whoever runs the init script) | |
| 61 | + | NODEUSER=nodeuser:nodegroup # USER who OWNS the daemon process (no matter whoever runs the init script) | |
| 66 | 62 | # user:group (if no group is specified, the primary GID for that user is used) | |
| 67 | 63 | ||
| 68 | 64 | LOCAL_VAR_RUN=/usr/local/var/run # in case the init script is run by non-root user, you need to | |
| @@ -111,7 +107,7 @@ SCRIPTNAME=/etc/init.d/$INIT_SCRIPT_NAME | |||
| 111 | 107 | . /lib/lsb/init-functions | |
| 112 | 108 | ||
| 113 | 109 | # uncomment to override system setting | |
| 114 | - | # VERBOSE=yes | |
| 110 | + | VERBOSE=yes | |
| 115 | 111 | ||
| 116 | 112 | # | |
| 117 | 113 | # Function that starts the daemon/service | |
| @@ -123,14 +119,15 @@ do_start() | |||
| 123 | 119 | # 1 if daemon was already running | |
| 124 | 120 | # 2 if daemon could not be started | |
| 125 | 121 | start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $NODEUSER --background --exec $DAEMON --test > /dev/null \ | |
| 126 | - | || { [ "$VERBOSE" != no ] && log_daemon_msg " ---> Daemon already running $DESC" "$INIT_SCRIPT_NAME_NOEXT"; return 1; } | |
| 122 | + | || { [ "$VERBOSE" != no ] && log_progress_msg "---> Daemon already running.."; return 1; } | |
| 127 | 123 | start-stop-daemon --start --quiet --chuid $NODEUSER --make-pidfile --pidfile $PIDFILE --background --exec $DAEMON -- \ | |
| 128 | 124 | $DAEMON_ARGS \ | |
| 129 | - | || { [ "$VERBOSE" != no ] && log_daemon_msg " ---> could not be start $DESC" "$INIT_SCRIPT_NAME_NOEXT"; return 2; } | |
| 125 | + | || { [ "$VERBOSE" != no ] && log_progress_msg "---> could not be started"; return 2; } | |
| 130 | 126 | # Add code here, if necessary, that waits for the process to be ready | |
| 131 | 127 | # to handle requests from services started subsequently which depend | |
| 132 | 128 | # on this one. As a last resort, sleep for some time. | |
| 133 | - | [ "$VERBOSE" != no ] && log_daemon_msg " ---> started $DESC" "$INIT_SCRIPT_NAME_NOEXT" | |
| 129 | + | [ "$VERBOSE" != no ] && log_progress_msg "---> started" | |
| 130 | + | return 0 | |
| 134 | 131 | } | |
| 135 | 132 | ||
| 136 | 133 | # | |
| @@ -143,7 +140,7 @@ do_stop() | |||
| 143 | 140 | # 1 if daemon was already stopped | |
| 144 | 141 | # 2 if daemon could not be stopped | |
| 145 | 142 | # other if a failure occurred | |
| 146 | - | start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --chuid $NODEUSER --name $DAEMON | |
| 143 | + | start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --chuid $NODEUSER --exec $DAEMON | |
| 147 | 144 | RETVAL="$?" | |
| 148 | 145 | #[ "$VERBOSE" != no ] && [ "$RETVAL" = 1 ] && log_daemon_msg " ---> SIGKILL failed => hardkill $DESC" "$INIT_SCRIPT_NAME_NOEXT" | |
| 149 | 146 | [ "$RETVAL" = 2 ] && return 2 | |
| @@ -157,8 +154,8 @@ do_stop() | |||
| 157 | 154 | [ "$?" = 2 ] && return 2 | |
| 158 | 155 | # Many daemons don't delete their pidfiles when they exit. | |
| 159 | 156 | rm -f $PIDFILE | |
| 160 | - | [ "$VERBOSE" != no ] && [ "$RETVAL" = 1 ] && log_daemon_msg " ---> $DESC not running" "$INIT_SCRIPT_NAME_NOEXT" | |
| 161 | - | [ "$VERBOSE" != no -a "$RETVAL" = 0 ] && log_daemon_msg " ---> $DESC stopped" "$INIT_SCRIPT_NAME_NOEXT" | |
| 157 | + | [ "$VERBOSE" != no ] && [ "$RETVAL" = 1 ] && log_progress_msg "---> was not running.." | |
| 158 | + | [ "$VERBOSE" != no -a "$RETVAL" = 0 ] && log_progress_msg "---> stopped" | |
| 162 | 159 | return "$RETVAL" | |
| 163 | 160 | } | |
| 164 | 161 | ||
| @@ -194,15 +191,15 @@ do_status() { | |||
| 194 | 191 | ||
| 195 | 192 | if [ -n "$RUNNING" ]; then | |
| 196 | 193 | if [ $ISPIDACTIVE ]; then | |
| 197 | - | log_success_msg "$INIT_SCRIPT_NAME_NOEXT (launched by $USER) (--chuid $NODEUSER) is running" | |
| 194 | + | log_success_msg "$INIT_SCRIPT_NAME_NOEXT launched by $NODEUSER is running" | |
| 198 | 195 | exit 0 | |
| 199 | 196 | fi | |
| 200 | 197 | else | |
| 201 | 198 | if [ -f $PIDFILE ]; then | |
| 202 | - | log_success_msg "$INIT_SCRIPT_NAME_NOEXT (launched by $USER) (--chuid $NODEUSER) is not running, phantom pidfile $PIDFILE" | |
| 199 | + | log_success_msg "$INIT_SCRIPT_NAME_NOEXT launched by $NODEUSER is not running, phantom pidfile $PIDFILE" | |
| 203 | 200 | exit 1 | |
| 204 | 201 | else | |
| 205 | - | log_success_msg "no instance launched by $USER, of $INIT_SCRIPT_NAME_NOEXT (--chuid $NODEUSER) found" | |
| 202 | + | log_success_msg "Not running. No instance of $INIT_SCRIPT_NAME_NOEXT launched $NODEUSER found" | |
| 206 | 203 | exit 3 | |
| 207 | 204 | fi | |
| 208 | 205 | fi | |
| @@ -249,7 +246,7 @@ case "$1" in | |||
| 249 | 246 | # If the "reload" option is implemented then remove the | |
| 250 | 247 | # 'force-reload' alias | |
| 251 | 248 | # | |
| 252 | - | log_daemon_msg "Restarting $DESC" "$INIT_SCRIPT_NAME_NOEXT" | |
| 249 | + | [ "$VERBOSE" != no ] && log_daemon_msg "Restarting $DESC" "$INIT_SCRIPT_NAME_NOEXT" | |
| 253 | 250 | do_stop | |
| 254 | 251 | case "$?" in | |
| 255 | 252 | 0|1) | |
| @@ -261,7 +258,7 @@ case "$1" in | |||
| 261 | 258 | esac | |
| 262 | 259 | ;; | |
| 263 | 260 | *) | |
| 264 | - | # Failed to stop | |
| 261 | + | # Failed to stop | |
| 265 | 262 | log_end_msg 1 | |
| 266 | 263 | ;; | |
| 267 | 264 | esac | |
Olivier Bazoud revised this gist 13 years ago. Go to revision
1 file changed, 1 insertion, 1 deletion
node_debian_init.sh
| @@ -83,7 +83,7 @@ NODECMD="exec $DAEMON $DAEMON_ARGS >>$LOCAL_VAR_LOGS 2>&1" # node command | |||
| 83 | 83 | # (Nothing else to modify from this point on...) # | |
| 84 | 84 | # ------------------------------------------------------------------------------ | |
| 85 | 85 | ||
| 86 | - | [ ! -d "$LOCAL_VAR_LOGS_DIR" ] || { mkdir "$LOCAL_VAR_LOGS_DIR" -p } | |
| 86 | + | [ ! -d "$LOCAL_VAR_LOGS_DIR" ] || { mkdir "$LOCAL_VAR_LOGS_DIR" -p; } | |
| 87 | 87 | ||
| 88 | 88 | # Do NOT "set -e" | |
| 89 | 89 | ||
Peter Host revised this gist 14 years ago. Go to revision
1 file changed, 1 insertion, 1 deletion
node_debian_init.sh
| @@ -1,4 +1,4 @@ | |||
| 1 | - | #! /bin/sh | |
| 1 | + | #!/bin/sh | |
| 2 | 2 | # ------------------------------------------------------------------------------ | |
| 3 | 3 | # SOME INFOS : fairly standard (debian) init script. | |
| 4 | 4 | # Note that node doesn't create a PID file (hence --make-pidfile) | |