Skip to content

Commit

Permalink
Improve upstart.tpl shell script syntax
Browse files Browse the repository at this point in the history
- Use spaces instead of tab for indent
- Replace deprecated `command` with $(command)
- Add missing quote to variable reference
- Separate variable declaration and assign to avoid masking return values
  • Loading branch information
PeterDaveHello committed Jul 2, 2018
1 parent ca968cf commit d0a4c02
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/templates/init-scripts/upstart.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ MAX_OPEN_FILES=

# overwrite settings from default file
if [ -f "$DEFAULT" ]; then
. "$DEFAULT"
. "$DEFAULT"
fi

# set maximum open files if set
Expand All @@ -33,7 +33,8 @@ if [ -n "$MAX_OPEN_FILES" ]; then
fi

get_user_shell() {
local shell=$(getent passwd ${1:-`whoami`} | cut -d: -f7 | sed -e 's/[[:space:]]*$//')
local shell
shell=$(getent passwd "${1:-$(whoami)}" | cut -d: -f7 | sed -e 's/[[:space:]]*$//')

if [[ $shell == *"/sbin/nologin" ]] || [[ $shell == "/bin/false" ]] || [[ -z "$shell" ]];
then
Expand All @@ -44,8 +45,9 @@ get_user_shell() {
}

super() {
local shell=$(get_user_shell $USER)
su - $USER -s $shell -c "PATH=$PATH; PM2_HOME=$PM2_HOME $*"
local shell
shell=$(get_user_shell $USER)
su - "$USER" -s "$shell" -c "PATH=$PATH; PM2_HOME=$PM2_HOME $*"
}

start() {
Expand Down

0 comments on commit d0a4c02

Please sign in to comment.