Run a shell script and immediately background it, however keep the ability to inspect its output

To ‘background’ a process when you start it Simply add an ampersand (&) after the command. If the program writes to standard out, it will still write to your console / terminal. To foreground the process Simply use the fg command. You can see a list of jobs in the background with jobs. For example: … Read more

How to convert a java program to daemon with jsvc?

Java class: package example; import java.util.Date; import java.util.Timer; import java.util.TimerTask; import org.apache.commons.daemon.*; class EchoTask extends TimerTask { @Override public void run() { System.out.println(new Date() + ” running …”); } } public class Main implements Daemon { private static Timer timer = null; public static void main(String[] args) { timer = new Timer(); timer.schedule(new EchoTask(), 0, … Read more

How do I run a Node.js application as its own process?

2016 answer: nearly every Linux distribution comes with systemd, which means forever, monit, PM2, etc. are no longer necessary – your OS already handles these tasks. Make a myapp.service file (replacing ‘myapp’ with your app’s name, obviously): [Unit] Description=My app [Service] ExecStart=/var/www/myapp/app.js Restart=always User=nobody # Note Debian/Ubuntu uses ‘nogroup’, RHEL/Fedora uses ‘nobody’ Group=nogroup Environment=PATH=/usr/bin:/usr/local/bin Environment=NODE_ENV=production … Read more

Python script as linux service/daemon

Assuming your daemon has some way of continually running (some event loop, twisted, whatever), you can try to use upstart. Here’s an example upstart config for a hypothetical Python service: description “My service” author “Some Dude <[email protected]>” start on runlevel [234] stop on runlevel [0156] chdir /some/dir exec /some/dir/script.py respawn If you save this as … Read more

Is it wise to use PHP for a daemon?

As others have noted, various versions of PHP have issues with their garbage collectors. Of course, if you know that your version does not have such issues, you eliminate that problem. The point is, you don’t know (for sure) until you write the daemon and run it through valgrind to see if the installed PHP … Read more