Flag to name jobs without using `immortaldir`
NovaRemitly opened this issue · comments
For lightweight or temporary usage of immortal
, it's still useful to be able to refer to jobs by name. I'm thinking it could work something like this:
$ immortal -n datelog -l out.txt /bin/sh -c "date && sleep 5"
$ immortalctl status
PID Up Down Name CMD
92315 4.3s datelog /bin/sh -c date && sleep 5
$ immortalctl exit datelog
PID Up Down Name CMD
I think this should be fairly straightforward to implement. If it's a feature that you agree would be useful, I would be happy to look into implementing it myself.
Hi, the reason for not using names and using the PIDs is because sometimes the same process may be required to run multiple times within the same session and by having the same name they would collide.
For permanent process, persistent to reboots is better to create a small datelog.yml file, for example:
cmd: date
log:
file: /var/log/app-1.log
age: 86400 # seconds
num: 7 # int
size: 1 # MegaBytes
And put it within the immortaldir
/usr/local/etc/immortaldir/datelog.yml
By doing this, you could then identify the process by a given name:
$ immortalctl exit datelog
I forgot the IMMORTAL_SDIR
environment that can be used with the -ctl
option so to achive what you want just need to do something like:
export IMMORTAL_SDIR=/tmp/immortal
And then just run the command like this:
immortal -ctl datelog -l out.txt /bin/sh -c "date && sleep 5"
later by just typing immortalctl
you can see the name:
$ immortalctl
PID Up Down Name CMD
88716 3.0s datelog /bin/sh -c date && sleep 5
If the environment var IMMORTAL_SDIR
is not set, -ctl
defaults to /var/run/immortal/<name>
If you always want to use names instead of PIDs, just need to always set the IMMORTAL_SDIR
to the path where you would like to create the immortal.sock
Please give a try and let me know if working from your side.
Yes, the -ctl
option is what I was looking for. Tested it out and it works perfectly. Thank you for the help, and for making such an awesome tool! 😃