su - phil -c "/usr/bin/screen -dmS solr /opt/start_solr141.sh"
Let’s look at what’s happening here, first we use su
to run this as a different user, then we define the user (phil), then in the command, called out by the -c and encased in double quotes, using the screen command with -smS to start a new detached session, giving it a name, and finally giving it a command to run in that detached screen session. Now put this line in something like /etc/rc.local, and it will run that command, in a detached screen session, automatically on boot. In this case a shell script to kick off the Apache Solr process in a detached screen session that you can attach to later. Yes, I could have written a ‘real’ start-up script and made it into an init.d file, and I know you can run Solr under Tomcat, and I do, on production, but with test and development versions it’s nice to be able to just spin new ones up quickly like this. Plus you can use the above line to start anything in a screen at boot, which is all I wanted to show in this example. Thanks!