Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.56k stars 2.62k forks source link

pm2 startup not working on Ubuntu Debian #2907

Closed pensierinmusica closed 7 years ago

pensierinmusica commented 7 years ago

Hi,

When I run pm2 startup on Ubuntu Debian I get:

[PM2][ERROR] Init system not found

I've also tried pm2 startup ubuntu but I get:

/bin/sh: 1: systemctl: not found

Can you please help out? Thx!

vmarchaud commented 7 years ago

Which version of debian ? Have you systemd or another init system ?

pensierinmusica commented 7 years ago

Which version of debian?

7.11 (Debian Wheezy)

Have you systemd or another init system ?

How do I find out?

vmarchaud commented 7 years ago

By default the init system in debian is systemd and the systemctl is the default one. If it isn't inside your PATH that means you may have a customized debian version and i can't help you on this. Try with pm2 startup upstart or pm2 startup systemv

pensierinmusica commented 7 years ago

I have a standard Debian version.

This is the output from the two command you suggested:

# FIRST ONE

$ pm2 startup upstart

[PM2][ERROR] Init system not found
Platform upstart
Template
#!/bin/bash
### BEGIN INIT INFO
# Provides:        pm2
# Required-Start:  $local_fs $remote_fs $network
# Required-Stop:   $local_fs $remote_fs $network
# Default-Start:   2 3 4 5
# Default-Stop:    0 1 6
# Short-Description: PM2 Init script
# Description: PM2 process manager
### END INIT INFO

NAME=pm2
PM2=/usr/local/nvm/versions/node/v7.10.0/lib/node_modules/pm2/bin/pm2
USER=me
DEFAULT=/etc/default/$NAME

export PATH=/usr/local/nvm/versions/node/v7.10.0/bin:$PATH
export PM2_HOME="/home/me/.pm2"

# The following variables can be overwritten in $DEFAULT

# maximum number of open files
MAX_OPEN_FILES=

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

# set maximum open files if set
if [ -n "$MAX_OPEN_FILES" ]; then
    ulimit -n $MAX_OPEN_FILES
fi

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

    if [[ $shell == *"/sbin/nologin" ]] || [[ $shell == "/bin/false" ]] || [[ -z "$shell" ]];
    then
      shell="/bin/bash"
    fi

    echo "$shell"
}

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

start() {
    echo "Starting $NAME"
    super $PM2 resurrect
}

stop() {
    super $PM2 kill
}

restart() {
    echo "Restarting $NAME"
    stop
    start
}

reload() {
    echo "Reloading $NAME"
    super $PM2 reload all
}

status() {
    echo "Status for $NAME:"
    super $PM2 list
    RETVAL=$?
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status
        ;;
    restart)
        restart
        ;;
    reload)
        reload
        ;;
    force-reload)
        reload
        ;;
    *)
        echo "Usage: {start|stop|status|restart|reload|force-reload}"
        exit 1
        ;;
esac
exit $RETVAL

Target path
/etc/init.d/pm2-me
Command list
[ 'chmod +x /etc/init.d/pm2-me',
  'mkdir -p /var/lock/subsys',
  'touch /var/lock/subsys/pm2-me',
  'update-rc.d pm2-me defaults' ]
[PM2] Writing init configuration in /etc/init.d/pm2-me
[PM2] Making script booting at startup...
>>> Executing chmod +x /etc/init.d/pm2-me
[DONE] 
>>> Executing mkdir -p /var/lock/subsys
[DONE] 
>>> Executing touch /var/lock/subsys/pm2-me
[DONE] 
>>> Executing update-rc.d pm2-me defaults
/bin/sh: 1: update-rc.d: not found
[ERROR] Exit code : 127
[PM2][ERROR] update-rc.d pm2-me defaults failed, see error above.

# SECOND ONE

$ pm2 startup systemv

[PM2][ERROR] Init system not found
Platform systemv
Template
#!/bin/bash
### BEGIN INIT INFO
# Provides:        pm2
# Required-Start:  $local_fs $remote_fs $network
# Required-Stop:   $local_fs $remote_fs $network
# Default-Start:   2 3 4 5
# Default-Stop:    0 1 6
# Short-Description: PM2 Init script
# Description: PM2 process manager
### END INIT INFO

NAME=pm2
PM2=/usr/local/nvm/versions/node/v7.10.0/lib/node_modules/pm2/bin/pm2
USER=me
DEFAULT=/etc/default/$NAME

export PATH=/usr/local/nvm/versions/node/v7.10.0/bin:$PATH
export PM2_HOME="/home/me/.pm2"

# The following variables can be overwritten in $DEFAULT

# maximum number of open files
MAX_OPEN_FILES=

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

# set maximum open files if set
if [ -n "$MAX_OPEN_FILES" ]; then
    ulimit -n $MAX_OPEN_FILES
fi

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

    if [[ $shell == *"/sbin/nologin" ]] || [[ $shell == "/bin/false" ]] || [[ -z "$shell" ]];
    then
      shell="/bin/bash"
    fi

    echo "$shell"
}

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

start() {
    echo "Starting $NAME"
    super $PM2 resurrect
}

stop() {
    super $PM2 kill
}

restart() {
    echo "Restarting $NAME"
    stop
    start
}

reload() {
    echo "Reloading $NAME"
    super $PM2 reload all
}

status() {
    echo "Status for $NAME:"
    super $PM2 list
    RETVAL=$?
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status
        ;;
    restart)
        restart
        ;;
    reload)
        reload
        ;;
    force-reload)
        reload
        ;;
    *)
        echo "Usage: {start|stop|status|restart|reload|force-reload}"
        exit 1
        ;;
esac
exit $RETVAL

Target path
/etc/init.d/pm2-me
Command list
[ 'chmod +x /etc/init.d/pm2-me',
  'mkdir -p /var/lock/subsys',
  'touch /var/lock/subsys/pm2-me',
  'chkconfig --add pm2-me',
  'chkconfig pm2-me on',
  'initctl list' ]
[PM2] Writing init configuration in /etc/init.d/pm2-me
[PM2] Making script booting at startup...
>>> Executing chmod +x /etc/init.d/pm2-me
[DONE] 
>>> Executing mkdir -p /var/lock/subsys
[DONE] 
>>> Executing touch /var/lock/subsys/pm2-me
[DONE] 
>>> Executing chkconfig --add pm2-me
/bin/sh: 1: chkconfig: not found
[ERROR] Exit code : 127
[PM2][ERROR] chkconfig --add pm2-me failed, see error above.

It doesn't work, can you please reopen this issue? @vmarchaud

vmarchaud commented 7 years ago

As i said, systemctl is the default command under debian 7 to manage systemd, the problem must come from your environment if you can't use it.

lahvey commented 6 years ago

@pensierinmusica, have you solved this problem? I came across again on Ubuntu 14.04.

If not run as root, it says [PM2][ERROR] Init system not found. If run pm2 startup upstart, it recommends the following command.

sudo env PATH=$PATH:/home/work/.nvm/versions/node/v8.12.0/bin /home/work/.nvm/versions/node/v8.12.0/lib/node_modules/pm2/bin/pm2 startup upstart -u work --hp /home/work

But if still fails.

[PM2][ERROR] Init system not found
Platform upstart
Template
#!/bin/bash
......
[PM2] [-] Executing: update-rc.d pm2-work defaults...
/bin/sh: 1: update-rc.d: not found
[ERROR] Exit code : 127
[PM2][ERROR] update-rc.d pm2-work defaults failed, see error above.
Unitech commented 6 years ago

Can you run pm2 startup without sudo or anything and copy paste the line indicated?

lahvey commented 6 years ago
[PM2][ERROR] Init system not found
/home/work/.nvm/versions/node/v8.12.0/lib/node_modules/pm2/lib/API/Startup.js:205
      throw new Error('Init system not found');
      ^

Error: Init system not found
    at API.CLI.startup (/home/work/.nvm/versions/node/v8.12.0/lib/node_modules/pm2/lib/API/Startup.js:205:13)
    at Command.<anonymous> (/home/work/.nvm/versions/node/v8.12.0/lib/node_modules/pm2/bin/pm2:744:9)
    at Command.listener (/home/work/.nvm/versions/node/v8.12.0/lib/node_modules/pm2/node_modules/commander/index.js:315:8)
    at emitTwo (events.js:126:13)
    at Command.emit (events.js:214:7)
    at Command.parseArgs (/home/work/.nvm/versions/node/v8.12.0/lib/node_modules/pm2/node_modules/commander/index.js:651:12)
    at Command.parse (/home/work/.nvm/versions/node/v8.12.0/lib/node_modules/pm2/node_modules/commander/index.js:474:21)
    at Timeout._onTimeout (/home/work/.nvm/versions/node/v8.12.0/lib/node_modules/pm2/bin/pm2:218:15)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)

newly installed Ubuntu 14.04 & nvm & node 8 & latest pm2.

This happens when I logged in with root and then su - work to run pm2 startup. Now I have solved it by restarting the system and login with work user directly.

gh0sthx commented 3 years ago

i have the same problem with docker,my docker node is lts-alpine

AjieDev commented 9 months ago

i think is not supported on VMs / Docker