
Ask HN: How to start a headless process and logout, continues? - ge96
The ultimate thing I&#x27;m working on is scraping and storing into database&#x2F;display into a web application. This is a personal project, I just want something that runs and when I get home I have new things to look at sort of thing.<p>I can do this from the perspective of a timed event with a web page open using JavaScript&#x2F;AJAX and PHP&#x2F;MYSQL. I&#x27;ll keep the PHP&#x2F;MYSQL part.<p>I tried to work with CRON but it didn&#x27;t work out well.<p>I recently bought a raspberry pi zero and setup a socket-server so to speak with a usb wifi adapter. So I want to be able to plug that into a wall, and then ssh into it to start a process, then that runs on its own. I&#x27;m just not sure what I&#x27;m looking for here, where I can have something trigger PHP but the process won&#x27;t end when I log out of SSH.<p>I&#x27;ve primarily (pretty much only) used a LAMP setup and haven&#x27;t done anything server side that involves processes. Usually everything is triggered by a client-facing thing. Whether it&#x27;s asynchronous loading or a get&#x2F;post. Not something that runs on its own outside of &#x2F;var&#x2F;www&#x2F;html (public)<p>I did come across CGI maybe that&#x27;s what I&#x27;m looking for. I&#x27;ve also seen that you can communicate with a MYSQL library with C++ I think last time I looked. It&#x27;s just that I&#x27;m used to using the PHP htmlsimpledom scraper.<p>I&#x27;ve been listening to a lot of podcasts talking about Go maybe that&#x27;s something but definitely outside of my scope at this time.
======
JoshTriplett
On the command line, take a look at "nohup". Programmatically, read about how
to "daemonize" (which involves calling fork() twice). And if you actually want
to run a server more persistently (not just keep a process running that you
launched from SSH), modern init systems (such as systemd) make that easy to do
by handling daemonization for you, such that your code doesn't need to do
anything special.

~~~
ge96
Cool, thanks a lot at least I have a direction to look. Yeah it's just odd to
me since I haven't done something like this before, how you keep something
running that isn't on the public/client-triggered side.

edit:

Actually a while back I did do a socket.io tutorial where you triggered the
process by terminal. Not sure if directly related, node was mentioned below. I
just wonder if you left the terminal would it end. Obviously not I don't think
since this is in practice now on the web and I doubt they just have terminals
open to keep a process running.

------
CyberFonic
The nohup approach with logging is the *nix way of doing ad-hoc stuff.

You could also look at mosh.org, it works like ssh, but handles disconnects
and re-connects well. You could even ^Z; bg to make your program run in
background and when you reconnect, you'd just do a fg to get it back into the
foreground. Since your shell doesn't get logged out, you'd be Ok.

~~~
ge96
Dang I have to admit I had to look up a lot of words that you mentioned.

One concern too is the ability to terminate it if it's essentially a
continuous poll/interval. Something is wrong, need to pass in a false variable
to stop the loop.

Thanks, will check this out.

------
onion2k
Trying to use a repeating timer event in a webpage to call a PHP script is a
pretty bad idea. It'd be horribly fragile. Your main options are really either
cron (which is a pain but once you get it working you're fine) or a long-
running process. If you really don't want to use cron then nodejs or python
would be pretty solid choices.

~~~
ge96
It's not that I don't want to use CRON, I just couldn't get it to work when I
tried. I tried with Ubuntu (root problem), then I tried debian (no root
problem) but it wouldn't execute. I think I did look at the dmesg or something
logs I can't remember the reason but yeah it wouldn't execute my test script.

Haven't touched nodejs or python but I am open to it. Thanks. I'm alright with
JavaScript (I can build things that I want in general) so maybe Node. Python
the syntax I'm not familiar (have to practice/use it)

Anyway thanks for the info

