I am going to be in the middle of nowhere for 10 days later this summer. I have a service that needs to stay running and if there is a problem when I am gone, I want to give one or two trusted people access to be able to restart that service. The service is a node.js application and even though they are very technical, I want it to be as simple as running a script via SSH (or a better option if there is one). What would be the best approach to accomplish this?
4 Answers
To avoid the need for a second person altogether, you should probably be using a watchdog type software to keep the service up. There are many different tools used on Linux to do this, such as:
- Monit: http://mmonit.com/monit/
- Upstart: http://upstart.ubuntu.com/
- Daemontools: http://cr.yp.to/daemontools.html
- Launchtool: http://people.debian.org/~enrico/launchtool.html
Luckily, there is a node.js specific app called 'forever
' that will accomplish this for you easily. Here is a very helpful tutorial on how to use it.
The quick way is:
npm install forever -g
forever start app.js
-
I do use forever. The problem is that the service I want to give access to is not usually running and needs to be started while I am gone. Jul 10, 2012 at 16:16
-
In this case, I would have suggested setting up a cron job to start it once via forever before you will be leaving ;-) Jul 10, 2012 at 18:18
-
It is a replacement bot for a Turntable.fm room. The other is getting packed in a box for a week. Timing isn't something I control. I am using the answer for now and will be shutting it down when I get back. Jul 10, 2012 at 18:21
-
Perhaps in this case designating a co-pilot is best. Good luck with the bot ;-) Jul 10, 2012 at 21:18
Configure sudo
so these two users can execute the necessary commands to stop/star/whatever the service.
The easiest off course is if you have an init script that does all the required things. Then all you need is to grant these users /sbin/service <servicename> ...
or similar depending on your distro.
That way you don't have to change anything to your setup and you're certain everything will be started with all the correct parameters and settings and such.
Just setup additional account for trusted people. Allow for this account only start/stop/restart operation for node.js application. After all, you could manage your app with following example script:
#!/bin/bash
command=$1
ssh user@host "your-app $command"
After that run it like this:
script.sh restart
- Give them a normal user.
- Put your desired command in their path.
Set the SETUID flag for your executable.
# chmod u+s [your executable file for service restart]