lanceseidman / PiCAST

PiCAST turns your $35 Raspberry Pi in to a Chromecast like Device.
https://munchron.com
1.77k stars 264 forks source link

Forever errors out and fails to start PiCAST v3.0 #34

Closed S0AndS0 closed 2 years ago

S0AndS0 commented 8 years ago

Modification Notes

First off I only had to fix two lines to get everything saying that it was installing correctly, however, after starting a modding I couldn't help myself from adding a few more tweeks to the code. I forked your code yesterday and will be making a push latter today to that branch of slight changes made to make the installer a bit more robust; take a look at the following bug report and let me know what I need to change to get the js and services bits working please.

same as /etc/init.d/picast file's start command but without exec to keep session alive

pi@raspberrypi:~ $ forever start --sourceDir=/home/pi/PiCAST -p /var/run/forever picast.js
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: picast.js

fs.js:436
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory '/var/run/forever/Cmv2.log'
    at Object.fs.openSync (fs.js:436:18)
    at Object.forever.startDaemon (/usr/local/lib/node_modules/forever/lib/forever.js:460:14)
    at /usr/local/lib/node_modules/forever/lib/forever/cli.js:315:15
    at /usr/local/lib/node_modules/forever/lib/forever/cli.js:161:5
    at /usr/local/lib/node_modules/forever/lib/forever.js:412:11                                                       at Object.oncomplete (fs.js:107:15)
pi@raspberrypi:~ $

Atempt to change directories & manually start

same as sh ~/PiCAST/picast_start.sh script

pi@raspberrypi:~ $ cd /home/pi/PiCAST/
pi@raspberrypi:~/PiCAST $ ls
picast.js  picast_start.sh  picast_stop.sh
pi@raspberrypi:~/PiCAST $ cat picast_start.sh
echo "Starting PiCAST3..."
forever start picast.js
pi@raspberrypi:~/PiCAST $ forever start picast.js                                                                  warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: picast.js
pi@raspberrypi:~/PiCAST $ ps aux | grep picast | grep -v grep
pi       21617  0.5  2.6  39596 23340 ?        Ssl  09:26   0:02 /usr/bin/nodejs /usr/local/lib/node_modules/forever/bin/monitor picast.js
pi@raspberrypi:~/PiCAST $ sudo netstat -plant | grep 3000 || echo "No port found listening"
No port found listening

Atempt to run as Daemon

should be the same as running /etc/init.d/picast start command with root privlages

pi@raspberrypi:~/PiCAST $ sudo service picast start
Job for picast.service failed. See 'systemctl status picast.service' and 'journalctl -xn' for details.
pi@raspberrypi:~/PiCAST $ sudo systemctl status -l picast.service
 picast.service - (null)
   Loaded: loaded (/etc/init.d/picast)
   Active: failed (Result: exit-code) since Fri 2016-05-06 09:40:54 PDT; 42s ago
  Process: 21776 ExecStart=/etc/init.d/picast start (code=exited, status=255)

May 06 09:40:54 raspberrypi picast[21776]: warn:    --minUptime not set. Defaulting to: 1000ms
May 06 09:40:54 raspberrypi picast[21776]: warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
May 06 09:40:54 raspberrypi picast[21776]: info:    Forever processing file: picast.js
May 06 09:40:54 raspberrypi picast[21776]: error:   Cannot start forever
May 06 09:40:54 raspberrypi picast[21776]: error:   script /PiCAST/picast.js does not exist.
May 06 09:40:54 raspberrypi systemd[1]: picast.service: control process exited, code=exited status=255
May 06 09:40:54 raspberrypi systemd[1]: Failed to start (null).
May 06 09:40:54 raspberrypi systemd[1]: Unit picast.service entered failed state.
pi@raspberrypi:~/PiCAST $ journalctl -xn
No journal files were found.
pi@raspberrypi:~/PiCAST $ sudo journalctl -xn | grep -E "PiCAST|picast"
May 06 09:44:55 raspberrypi sudo[21856]: pi : TTY=pts/0 ; PWD=/home/pi/PiCAST ; USER=root ; COMMAND=/bin/journalctl
pi@raspberrypi:~/PiCAST $ ps aux | grep picast | grep -v grep || echo "No process found by that name"
No process found by that name

Notes on RPi modle used to test PICAST v3.0

Here are the specs of my RPi (it is a version 2B or RPiB+2?... it's the one with nearly a gig'o'ram and four cores to process with)

pi@raspberrypi:~/PiCAST $ cat /etc/*-release | grep -vE 'HOME_URL|SUPPORT_URL|BUG_REPORT_URL' && cat /proc/cpuinfo | grep -vE 'Serial'
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
processor       : 0
model name      : ARMv7 Processor rev 5 (v7l)
BogoMIPS        : 38.40
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xc07
CPU revision    : 5
# ...
# ... Above is repeated per CPU core, edited out redundent info
# ...
Hardware        : BCM2709
Revision        : a01041

Final thoughts

Bassed off error given and that browsers could not connect on http://RPi_IP:3000/yt-stream/even when I managed to force the process to stay alive via forever start picast.js command from wthin ~/PiCAST directory it seems to be something within picast.js or package.json that is missing or causing errors. If you clue me in on possible edits to these files I'll try'em out.

Aevyz commented 8 years ago

Mind I ask how you are installing forever, it seems to fail by me all the time.

The failure is that: picast_start.sh: forever: not found

S0AndS0 commented 8 years ago

I don't mind at all; npm commands didn't need changing, setup.sh did just fine there.

echo "Downloading and installing 'forever' and 'forever-monitor' via 'npm' to allow PiCAST to run without active terminal"
sudo npm install forever -g
sudo npm install forever-monitor -g

And for good messure here's forever running some help docs and checks, though I couldn't find a "print version" option

pi@raspberrypi:~/PiCAST $ forever list
info:    No forever processes running
pi@raspberrypi:~/PiCAST $ forever --help | grep version
pi@raspberrypi:~/PiCAST $ forever --help | grep debug
help:      -d, --debug      Forces forever to log debug output

So it looks like the CLI is aware of forever as a command. Now to check out the --debug option

pi@raspberrypi:~/PiCAST $ forever start --debug --sourceDir=/home/pi/PiCAST -p /var/run/forever picast.js          warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: picast.js

fs.js:436
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory '/var/run/forever/CoJV.log'
    at Object.fs.openSync (fs.js:436:18)
    at Object.forever.startDaemon (/usr/local/lib/node_modules/forever/lib/forever.js:460:14)
    at /usr/local/lib/node_modules/forever/lib/forever/cli.js:315:15
    at /usr/local/lib/node_modules/forever/lib/forever/cli.js:161:5
    at /usr/local/lib/node_modules/forever/lib/forever.js:412:11
    at Object.oncomplete (fs.js:107:15)
pi@raspberrypi:~/PiCAST $ sudo netstat -plant | grep 3000 || echo "No port by that number found listening"
No port by that number found listening
pi@raspberrypi:~/PiCAST $ ps aux | grep picast | grep -v grep || echo "No process found by that name"
No process found by that name
pi@raspberrypi:~/PiCAST $ forever stop --debug --sourceDir=/home/pi/PiCAST -p /var/run/forever picast.js
error:   Forever cannot find process with id: picast.js
pi@raspberrypi:~/PiCAST $ sudo journalctl -xn | grep -E "PiCAST|picast"
May 06 12:16:28 raspberrypi sudo[23055]: pi : TTY=pts/0 ; PWD=/home/pi/PiCAST ; USER=root ; COMMAND=/bin/netstat -plant
May 06 12:17:10 raspberrypi sudo[23098]: pi : TTY=pts/0 ; PWD=/home/pi/PiCAST ; USER=root ; COMMAND=/bin/journalctl -xn
pi@raspberrypi:~/PiCAST $ sudo systemctl status -l picast.service                                                 picast.service - (null)
   ded: loaded (/etc/init.d/picast)
   Active: failed (Result: exit-code) since Fri 2016-05-06 09:40:54 PDT; 2h 36min ago
  Process: 21776 ExecStart=/etc/init.d/picast start (code=exited, status=255)

May 06 09:40:54 raspberrypi picast[21776]: warn:    --minUptime not set. Defaulting to: 1000ms
May 06 09:40:54 raspberrypi picast[21776]: warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
May 06 09:40:54 raspberrypi picast[21776]: info:    Forever processing file: picast.js
May 06 09:40:54 raspberrypi picast[21776]: error:   Cannot start forever
May 06 09:40:54 raspberrypi picast[21776]: error:   script /PiCAST/picast.js does not exist.
May 06 09:40:54 raspberrypi systemd[1]: picast.service: control process exited, code=exited status=255
May 06 09:40:54 raspberrypi systemd[1]: Failed to start (null).
May 06 09:40:54 raspberrypi systemd[1]: Unit picast.service entered failed state.

And trying to run without --sourceDir option and instead using full path to define service.js

pi@raspberrypi:~/PiCAST $ forever start --debug -p /var/run/forever /home/pi/PiCAST/picast.js
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: /home/pi/PiCAST/picast.js

fs.js:436
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory '/var/run/forever/pUBd.log'
    at Object.fs.openSync (fs.js:436:18)
    at Object.forever.startDaemon (/usr/local/lib/node_modules/forever/lib/forever.js:460:14)
    at /usr/local/lib/node_modules/forever/lib/forever/cli.js:315:15
    at /usr/local/lib/node_modules/forever/lib/forever/cli.js:161:5
    at /usr/local/lib/node_modules/forever/lib/forever.js:412:11
    at Object.oncomplete (fs.js:107:15)
pi@raspberrypi:~/PiCAST $ sudo systemctl status -l picast.service
 picast.service - (null)
   Loaded: loaded (/etc/init.d/picast)
   Active: failed (Result: exit-code) since Fri 2016-05-06 09:40:54 PDT; 2h 41min ago
  Process: 21776 ExecStart=/etc/init.d/picast start (code=exited, status=255)

May 06 09:40:54 raspberrypi picast[21776]: warn:    --minUptime not set. Defaulting to: 1000ms
May 06 09:40:54 raspberrypi picast[21776]: warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
May 06 09:40:54 raspberrypi picast[21776]: info:    Forever processing file: picast.js
May 06 09:40:54 raspberrypi picast[21776]: error:   Cannot start forever
May 06 09:40:54 raspberrypi picast[21776]: error:   script /PiCAST/picast.js does not exist.
May 06 09:40:54 raspberrypi systemd[1]: picast.service: control process exited, code=exited status=255
May 06 09:40:54 raspberrypi systemd[1]: Failed to start (null).
May 06 09:40:54 raspberrypi systemd[1]: Unit picast.service entered failed state.
pi@raspberrypi:~/PiCAST $ sudo journalctl -xn | grep -E "PiCAST|picast"
May 06 12:17:42 raspberrypi sudo[23114]: pi : TTY=pts/0 ; PWD=/home/pi/PiCAST ; USER=root ; COMMAND=/bin/systemctl status -l picast.service
May 06 12:22:27 raspberrypi sudo[23154]: pi : TTY=pts/0 ; PWD=/home/pi/PiCAST ; USER=root ; COMMAND=/bin/systemctl status -l picast.service
May 06 12:22:37 raspberrypi sudo[23168]: pi : TTY=pts/0 ; PWD=/home/pi/PiCAST ; USER=root ; COMMAND=/bin/journalctl -xn
pi@raspberrypi:~/PiCAST $ ps aux | grep picast | grep -v grep || echo "No process found by that name"
No process found by that name

Errors noted

Error: ENOENT, no such file or directory '/var/run/forever/CoJV.log'
# ... so, a missing directory eh?...
pi@raspberrypi:~/PiCAST $ ls -hal /var/run/forever
ls: cannot access /var/run/forever: No such file or directory
# ... Yep! haha I founds a bug... time to squish...
pi@raspberrypi:~/PiCAST $ sudo mkdir /var/run/forever
pi@raspberrypi:~/PiCAST $ forever start --debug -p /var/run/forever /home/pi/PiCAST/picast.js                      warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: /home/pi/PiCAST/picast.js

fs.js:436
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: EACCES, permission denied '/var/run/forever/T6jy.log'
    at Object.fs.openSync (fs.js:436:18)
    at Object.forever.startDaemon (/usr/local/lib/node_modules/forever/lib/forever.js:460:14)
    at /usr/local/lib/node_modules/forever/lib/forever/cli.js:315:15
    at /usr/local/lib/node_modules/forever/lib/forever/cli.js:161:5
    at /usr/local/lib/node_modules/forever/lib/forever.js:412:11
    at Object.oncomplete (fs.js:107:15)

Sweet a new error,

Error: EACCES, permission denied '/var/run/forever/T6jy.log'

one I think can be solved...

pi@raspberrypi:~/PiCAST $ sudo ls -hal /var/run/forever
total 0
drwxr-xr-x  2 root root  40 May  6 12:33 .
drwxr-xr-x 23 root root 780 May  6 12:33 ..
pi@raspberrypi:~/PiCAST $ sudo chown pi:pi /var/run/forever
pi@raspberrypi:~/PiCAST $ forever start --debug -p /var/run/forever /home/pi/PiCAST/picast.js
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: /home/pi/PiCAST/picast.js
pi@raspberrypi:~/PiCAST $ sudo netstat -plant | grep 3000 || echo "No port by that number found listening"         No port by that number found listening
pi@raspberrypi:~/PiCAST $ sudo ls -hal /var/run/forever
total 4.0K
drwxr-xr-x  2 pi   pi    60 May  6 12:35 .
drwxr-xr-x 23 root root 780 May  6 12:33 ..
-rw-r--r--  1 pi   pi   604 May  6 12:35 xQH2.log
pi@raspberrypi:~/PiCAST $ sudo journalctl -xn | grep -E "PiCAST|picast" | grep -vE "root" || echo "No report for $USER"
No report for pi
pi@raspberrypi:~/PiCAST $ ps aux | grep picast | grep -v grep || echo "No process found by that name"              pi       23447  3.6  2.7  39604 24308 ?        Ssl  12:35   0:02 /usr/bin/nodejs /usr/local/lib/node_modules/forever/bin/monitor /home/pi/PiCAST/picast.js

So again I've a false starter on PiCast services, now to try the start, stop script instead and see how that fares because it'll not have the file path defied as I did above manually and perhaps sudo can encurage forever to start...

pi@raspberrypi:~/PiCAST $ sudo service picast start
Warning: Unit file of picast.service changed on disk, 'systemctl daemon-reload' recommended.
Job for picast.service failed. See 'systemctl status picast.service' and 'journalctl -xn' for details.
pi@raspberrypi:~/PiCAST $ sudo systemctl daemon-reload
pi@raspberrypi:~/PiCAST $ sudo service picast start
Job for picast.service failed. See 'systemctl status picast.service' and 'journalctl -xn' for details.
pi@raspberrypi:~/PiCAST $ sudo service picast stop
pi@raspberrypi:~/PiCAST $ sudo journalctl -xn | grep -E "PiCAST|picast" | grep -vE "root" || echo "No report for $USER"
May 06 12:45:07 raspberrypi picast[23661]: error:   script ~/PiCAST/picast.js does not exist.
May 06 12:45:07 raspberrypi systemd[1]: picast.service: control process exited, code=exited status=255
-- Subject: Unit picast.service has failed
-- Unit picast.service has failed.
May 06 12:45:07 raspberrypi systemd[1]: Unit picast.service entered failed state.
pi@raspberrypi:~/PiCAST $ sudo systemctl status -l picast.service                                                   picast.service - (null)
   Loaded: loaded (/etc/init.d/picast)
   Active: failed (Result: exit-code) since Fri 2016-05-06 12:45:07 PDT; 2min 6s ago
  Process: 23661 ExecStart=/etc/init.d/picast start (code=exited, status=255)

May 06 12:45:07 raspberrypi picast[23661]: warn:    --minUptime not set. Defaulting to: 1000ms
May 06 12:45:07 raspberrypi picast[23661]: warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
May 06 12:45:07 raspberrypi picast[23661]: info:    Forever processing file: picast.js
May 06 12:45:07 raspberrypi picast[23661]: error:   Cannot start forever
May 06 12:45:07 raspberrypi picast[23661]: error:   script ~/PiCAST/picast.js does not exist.
May 06 12:45:07 raspberrypi systemd[1]: picast.service: control process exited, code=exited status=255
May 06 12:45:07 raspberrypi systemd[1]: Failed to start (null).
May 06 12:45:07 raspberrypi systemd[1]: Unit picast.service entered failed state.

Solutions found

Well /var/run/forever may need to be created if not present and permissions set because there are less errors when it has a directory to save files into, this is how the following was revieled

pi@raspberrypi:~/PiCAST $ cat /var/run/forever/xQH2.log                                                            
module.js:340
    throw err;
          ^
Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/pi/PiCAST/picast.js:3:15)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
error: Forever detected script exited with code: 8

While it is not the most helpfull error it is one that we where not getting before on my system... I'll clean up my edits now that I know that /var/fun/forever may or may not be auto-created upon install and make a push to GitHub...

Edit / Update

I've pushed the version that I've been re-writing to the fork I made, script named PiCast_installer_candidate.sh should be run with bash not sh to preform similar installation process but with a few sweet goodies added in for error checking/logging. All major changes have been noted in the Changes_Log.md file. Let me know if there's something I missed but I think it'll install a little faster on various RPi moddles too even though its a few lines longer.

TigerTape commented 8 years ago

This was a very helpful thread. I was getting similar issues on my RPi 2. I did the fixes:

sudo mkdir /var/run/forever
sudo chown pi:pi /var/run/forever

Which got me to the throw error and then from another forum I found this fix, which got PiCAST working:

rm -fr node_modules
npm i
S0AndS0 commented 8 years ago

@TigerTape that worked like nothing else! Thank you, but where did you find those last two commands?

I tried it without removing node_modules and was greated with a web prompt for the first time on port 3000 :-D

pi@raspberrypi:~ $ cd PiCAST/
pi@raspberrypi:~/PiCAST $ npm i
npm WARN package.json PiCAST@3.0.0 No README data
sys@0.0.1 node_modules/sys

express@4.13.4 node_modules/express
 escape-html@1.0.3
 array-flatten@1.1.1
 utils-merge@1.0.0
 cookie-signature@1.0.6
 merge-descriptors@1.0.1
 fresh@0.3.0
 methods@1.1.2
 range-parser@1.0.3
 vary@1.0.1
 path-to-regexp@0.1.7
 cookie@0.1.5
 parseurl@1.3.1
 content-type@1.0.2
 etag@1.7.0
 content-disposition@0.5.1
 serve-static@1.10.2
 depd@1.1.0
 qs@4.0.0
 on-finished@2.3.0 (ee-first@1.1.1)
 debug@2.2.0 (ms@0.7.1)
 finalhandler@0.4.1 (unpipe@1.0.0)
 proxy-addr@1.0.10 (forwarded@0.1.0, ipaddr.js@1.0.5)
 send@0.13.1 (destroy@1.0.4, statuses@1.2.1, ms@0.7.1, mime@1.3.4, http-errors@1.3.1)
 type-is@1.6.12 (media-typer@0.3.0, mime-types@2.1.11)
 accepts@1.2.13 (negotiator@0.5.3, mime-types@2.1.11)
pi@raspberrypi:~/PiCAST $ sudo netstat -plant
Active Internet connections (servers and established)

But the forever part still is a bit broken for me; I'll do more testing tomorrow when I've a bit of time and see if removing ~/PiCAST/node_modules fixes the rest. If that does fix it then changes will be eventually pushed to my fork for testing & review.

Thanks again @TigerTape, my house-mates will be estatic if this works.

lanceseidman commented 2 years ago

You have permission errors in one comment (try run as sudo). Another comment the script doesn't recognize your argument, not supported by PiCAST unless you write it into the software.