Octofarm: Empfohlen Automatischer Start von npm (unter Linux)?

Erstellt am 28. Apr. 2020  ·  5Kommentare  ·  Quelle: OctoFarm/OctoFarm

Gibt es eine empfohlene Methode zum automatischen Starten von npm nach Abschluss eines Bootvorgangs unter Linux? Ich habe versucht, dies mit init.d zu tun und hatte keinen Erfolg.

question

Hilfreichster Kommentar

Ich habe mit Ubuntu erfolgreich eine Systemd-Dienstdatei verwendet. Wie James sagt, kommt die neuere Version mit pm2. Mit pm2 können Sie pm2 startup ausführen und es erkennt Ihr Init-System und gibt einen Befehl aus, der ausgeführt wird, um die Startdateien zu generieren. Ich habe es gerade gemacht und es scheint ziemlich gut zu funktionieren.

VOLLSTÄNDIGE OFFENBARUNG: Ich hatte bis heute noch nie von pm2 gehört, also musste ich ein wenig recherchieren und das habe ich gefunden und getan und es scheint zu funktionieren.

Folgendes passiert, wenn ich pm2 startup run ausführe

ubuntu<strong i="10">@octofarm</strong>:~$ OctoFarm/node_modules/pm2/bin/pm2 startup
[PM2] Init System found: systemd
ubuntu
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/bin /home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu

Und nachdem ich den Befehl ausgeführt habe, sagte er mir:

ubuntu<strong i="14">@octofarm</strong>:~$ sudo env PATH=$PATH:/usr/bin /home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu
[PM2] Init System found: systemd
Platform systemd
Template
[Unit]
Description=PM2 process manager
Documentation=https://pm2.keymetrics.io/
After=network.target

[Service]
Type=forking
User=ubuntu
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/home/ubuntu/.pm2
PIDFile=/home/ubuntu/.pm2/pm2.pid
Restart=on-failure

ExecStart=/home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 resurrect
ExecReload=/home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 reload all
ExecStop=/home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 kill

[Install]
WantedBy=multi-user.target

Target path
/etc/systemd/system/pm2-ubuntu.service
Command list
[ 'systemctl enable pm2-ubuntu' ]
[PM2] Writing init configuration in /etc/systemd/system/pm2-ubuntu.service
[PM2] Making script booting at startup...
[PM2] [-] Executing: systemctl enable pm2-ubuntu...
Created symlink /etc/systemd/system/multi-user.target.wants/pm2-ubuntu.service → /etc/systemd/system/pm2-ubuntu.service.
[PM2] [v] Command successfully executed.
+---------------------------------------+
[PM2] Freeze a process list on reboot via:
$ pm2 save

[PM2] Remove init script via:
$ pm2 unstartup systemd

Alle 5 Kommentare

Viele verwenden ein npm-Paket namens pm2.

Sie können mit npm install pm2 -g installieren

Führen Sie dann Folgendes aus.

pm2 startup

Kopieren Sie die Ausgabe, die pm2 nach dem letzten liefert, und fügen Sie sie ein.

pm2 start app.js --name OctoFarm

pm2 save

https://pm2.keymetrics.io/docs/usage/startup/

Hier gibt es weitere Informationen dazu, lass es mich wissen, wenn du nicht weiterkommst.

1.1.5 kommt mit pm2 als Abhängigkeit und läuft damit. Ich werde hoffentlich in der Lage sein, die Startbefehle beim Booten zu aktivieren, so dass alles automatisch ist, aber ich habe mich noch nicht viel damit befasst.

Ich habe mit Ubuntu erfolgreich eine Systemd-Dienstdatei verwendet. Wie James sagt, kommt die neuere Version mit pm2. Mit pm2 können Sie pm2 startup ausführen und es erkennt Ihr Init-System und gibt einen Befehl aus, der ausgeführt wird, um die Startdateien zu generieren. Ich habe es gerade gemacht und es scheint ziemlich gut zu funktionieren.

VOLLSTÄNDIGE OFFENBARUNG: Ich hatte bis heute noch nie von pm2 gehört, also musste ich ein wenig recherchieren und das habe ich gefunden und getan und es scheint zu funktionieren.

Folgendes passiert, wenn ich pm2 startup run ausführe

ubuntu<strong i="10">@octofarm</strong>:~$ OctoFarm/node_modules/pm2/bin/pm2 startup
[PM2] Init System found: systemd
ubuntu
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/bin /home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu

Und nachdem ich den Befehl ausgeführt habe, sagte er mir:

ubuntu<strong i="14">@octofarm</strong>:~$ sudo env PATH=$PATH:/usr/bin /home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu
[PM2] Init System found: systemd
Platform systemd
Template
[Unit]
Description=PM2 process manager
Documentation=https://pm2.keymetrics.io/
After=network.target

[Service]
Type=forking
User=ubuntu
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/home/ubuntu/.pm2
PIDFile=/home/ubuntu/.pm2/pm2.pid
Restart=on-failure

ExecStart=/home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 resurrect
ExecReload=/home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 reload all
ExecStop=/home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 kill

[Install]
WantedBy=multi-user.target

Target path
/etc/systemd/system/pm2-ubuntu.service
Command list
[ 'systemctl enable pm2-ubuntu' ]
[PM2] Writing init configuration in /etc/systemd/system/pm2-ubuntu.service
[PM2] Making script booting at startup...
[PM2] [-] Executing: systemctl enable pm2-ubuntu...
Created symlink /etc/systemd/system/multi-user.target.wants/pm2-ubuntu.service → /etc/systemd/system/pm2-ubuntu.service.
[PM2] [v] Command successfully executed.
+---------------------------------------+
[PM2] Freeze a process list on reboot via:
$ pm2 save

[PM2] Remove init script via:
$ pm2 unstartup systemd

Danke für die schnelle Antwort an euch beide. Werde das heute später ausprobieren. Ich liebe / hasse Linux-Systeme - ungefähr 10 verschiedene Möglichkeiten, alles zu tun. Ich habe Ende der 1980er Jahre mit BSD Unix angefangen.

Kein Problem, ich lasse dies vorerst offen, um mich daran zu erinnern, einige Notizen zur README/Wiki hinzuzufügen

Installationsdokumente für diese plattformübergreifende Ausführung hinzugefügt added

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen

Verwandte Themen

tophattwaffle picture tophattwaffle  ·  10Kommentare

TomKamin1 picture TomKamin1  ·  18Kommentare

Nomad965 picture Nomad965  ·  15Kommentare

3DRemake picture 3DRemake  ·  7Kommentare

Polloman93 picture Polloman93  ·  6Kommentare