In the event of a system reboot, any existing screen/tmux sessions will no longer exist. Normally, this would require manually setting things back up and hopping back on the irc server using your preferred client.
With the help of the irc_chk script, you can schedule a cron job to periodically check for the existence of said screen/tmux session running an irc client, and start the whole thing up automatically if missing.
In order to successfully utilize the irc_chk script, you will need:
Configuring such things is beyond the scope of this document (perhaps another one will be written to address it).
The irc_chk script is designed to perform the check (and start things up if missing) as a default action. Just running the script manually will invoke this behavior.
It has a number of other options worth your consideration:
lab46:~$ irc_chk help irc_chk - check for existing terminal multiplexor + irc client session, and start if absent (restore after reboot). usage: irc_chk [OPTION]... behavior: this script is designed to be run from a crontab to automatically create a persistent irc session in the event of a system reboot. options: ======= setup - deploy job in crontab (defaults to check every 3 hours) irssi - use 'irssi' as irc client (overrides setting) weechat - use 'weechat' as irc client (overrides setting) screen - use 'screen' as terminal multiplexor (overrides setting) tmux - use 'tmux' as terminal multiplexor (overrides setting) verbose - increase verbosity (outputs progress of steps) debug - enable debugging (display discrete steps and results) quiet - no output (default) install - install script into local ~/bin directory upgrade - upgrade from master into local ~/bin directory norun - do not execute any commands (useful for debugging) check - check for possible changes/updates to irc_chk version - display version information and exit help - display this usage information and exit lab46:~$
For example, to check for available updates (if you've chosen to install a local copy):
lab46:~$ irc_chk check CHECK: Your version of irc_chk is up to date. lab46:~$
The script will make more noise if you give it the 'verbose' option on its command-line. It can occur in combination with pretty much any other option (conflicts with 'quiet', obviously):
lab46:~$ irc_chk verbose Host check SUCCEEDED. Using screen to encapsulate irssi session Script operations COMMENCING > irc server is running. > a screen session IS currently running [X] Script operations COMPLETE. lab46:~$
The script can also produce debugging information, useful for sorting out problems in script logic. Tacking on the 'debug' option will enable this (can be combined with other options, such as 'verbose').
Here we will view the current script version, applying both the 'verbose' and 'debug' options (all debug messages go to STDERR, and are prefixed with: '[debug]'
lab46:~$ irc_chk verbose version debug [debug] DEBUG mode ENABLED [debug] ======== DEBUG MODE VARIABLE REPORT ======== [debug] ABSPATH: /home/USERNAME/bin/irc_chk [debug] NAME: irc_chk [debug] USER: USERNAME [debug] DEBUGON: true [debug] VERBOSE: true [debug] D_SCRN: screen [debug] D_CLNT: irssi [debug] SCREEN: screen [debug] CLIENT: irssi [debug] SETUP: false [debug] INSTALL: false [debug] UPGRADE: false [debug] CHECK: false [debug] NORUN: false [debug] DOHELP: false [debug] VERSION: true [debug] IPADDR: 10.80.2.46 [debug] LAB_46: 10.80.2.46 [debug] NGIRCD: true [debug] TMX_UP: true [debug] IRC_UP: true [debug] ============================================ irc_chk-20180216-18 (md5sum: 2eba452c9e45d88e7bf6e579c2b3d926) lab46:~$
The script is designed for this to be the primary use case. When you run it with the 'setup' argument, it will install the following cron job into your crontab:
4 */3 * * * (USER=USERNAME /var/public/.haxx/scripts/irc_chk screen irssi)
Basically, it will do a check every 3 hours (on the 4th minute of that hour). If everything is okay, it silently exits. If your session is missing, it will recreate it.
Establishing your cron job is simple, and built into the script:
lab46:~$ /var/public/.haxx/scripts/irc_chk setup lab46:~$
…and that is it!
If you wanted to verify, you could list your cron jobs:
lab46:~$ crontab -l 4 */3 * * * (USER=USERNAME /var/public/.haxx/scripts/irc_chk screen irssi) lab46:~$
Then just let it be. If that is all you were after: congratulations! You are done.
It will check for any existing cron jobs (preserve them), and will NOT add duplicate irc_chk jobs.
By default, it assumes a screen+irssi combination. This can be changed as easily as providing your selections on the command line (or you can manually install it, and edit the D_SCRN and D_CLNT variables near the top of the script).
The script is designed to be minimal impact for use. Aside from your crontab receiving an added job, you do NOT need to copy or install any files for basic usage.
lab46:~$ /var/public/.haxx/scripts/irc_chk setup weechat lab46:~$
lab46:~$ /var/public/.haxx/scripts/irc_chk setup tmux irssi lab46:~$
lab46:~$ /var/public/.haxx/scripts/irc_chk setup tmux weechat lab46:~$
The irc_chk script was designed to both facilitate automatic restoration of irc sessions following a reboot (or other session disappearance), yet it was also designed to collect various scripting tricks of mine into one place, to share with those interested.
The script is extensively commented, and endeavors to maintain a consistent look throughout, so as to better follow the code. It makes use of functions, variables, command expansions, arrays, and more.
It has an 'install' option, should you wish to install a local copy in your ~/bin/ for modification (note that such is not necessary for base usage described above).
It also has a 'rorun' option, which will run through the motions but not actually perform any actions (it'll do the checks, but won't actually install the cronjob; it'll check for things, but won't start the screen+irssi session, etc.) This, especially in combination with 'verbose' and 'debug', can help to highlight the script's actions, be it for debugging a problem, adding new features, or just figuring out what it is doing.