zapty / forever-service

Provision node script as a service via forever, allowing it to automatically start on boot, working across various Linux distros and OS
https://github.com/zapty/forever-service
MIT License
594 stars 65 forks source link

Raspberry Pi --uid issue #99

Open imsunburnt opened 6 years ago

imsunburnt commented 6 years ago

When running on Raspberry Pi Jessie lite I had to add quotes around the --uid option in file templates/sysvinit/initd.template. According to forever -help: --uid Process uid, useful as a namespace for processes (must wrap in a string) e.g. forever start --uid "production" app.js

Without adding the quotes the command: sudo service service-name stop would not stop the service.

I did not verify if this problem exists in Ubuntu.

I made the following changes in templates/sysvinit/initd.template (in two places): FROM: --uid {{service}} TO: --uid "{{service}}"

SNIPPET: {% if runAsUser %} touch $LOGFILE chown {{runAsUser}} $LOGFILE

{{suprog}} - {{runAsUser}} -c "\
export FOREVER_ROOT={{foreverRoot}};\
{% if envVarsNameValueArray|default(false) %}{% for v in envVarsNameValueArray %}export {{ v[0] }}=$(printf "%q" {{v[1]}});\{% endfor %}{% else %}\{% endif %}
cd {{cwd}};\{% if applyUlimits %}
ulimit -f unlimited;\
ulimit -t unlimited;\
ulimit -v unlimited;\
ulimit -n 64000;\
ulimit -m unlimited;\
ulimit -u 32000;\{% endif %}
{{foreverPath}}forever \
    -a \
    -l $LOGFILE \
    --minUptime $MIN_UPTIME \
    --spinSleepTime $SPIN_SLEEP_TIME \
    --killSignal $KILL_SIGNAL \
    {{foreverOptions|default('')}} \
    --uid "{{service}}" \    <=========== added quotes ===================
    start {{script|default('app.js')}} {{scriptOptions|default('')}}" 2>&1 >/dev/null
{% else %}
# move to the directory from where the inital forever script was launched so that even if it is relative it works as expected
cd {{cwd}}

{% if applyUlimits %}
ulimit -f unlimited
ulimit -t unlimited
ulimit -v unlimited
ulimit -n 64000
ulimit -m unlimited
ulimit -u 32000
{% endif %}

{{foreverPath}}forever \
-a \
-l $LOGFILE \
--minUptime $MIN_UPTIME \
--spinSleepTime $SPIN_SLEEP_TIME \
--killSignal $KILL_SIGNAL \
{{foreverOptions|default('')}} \
--uid "{{service}}" \   <=========== added quotes ================
start {{script|default('app.js')}} {{scriptOptions|default('')}} 2>&1 >/dev/null
{% endif %}