Run interactive process as server

From FBSD_tips

Jump to: navigation, search

Back to "Admin building blocks"

[edit] Rationale

You may want to run an interactive process at system start and disassociate it from the terminal session. The example shown here is to use irssi to login to an IRC channel for purposes of logging that channel.

[edit] Setup

Prerequisite packages :

screen
irssi

Create a new user 'irssi' with via adduser.

> adduser 
Username: irssi
Full name:
Uid (Leave empty for default):
Login group [irssi]:
Login group is irssi. Invite irssi into other groups? []:
Login class [default]:
Shell (sh csh tcsh bash rbash nologin) [sh]:
Home directory [/home/irssi]:
Use password-based authentication? [yes]:
Use an empty password? (yes/no) [no]:
Use a random password? (yes/no) [no]:
Enter password:
Enter password again:
Lock out the account after creation? [no]:
Username   : irssi
Password   : *****
Full Name  :
Uid        : 1007
Class      :
Groups     : irssi
Home       : /home/irssi
Shell      : /bin/sh
Locked     : no
OK? (yes/no): yes
adduser: INFO: Successfully added (irssi) to the user database.
Add another user? (yes/no): no
Goodbye!

Now edit the irssi user's crontab and add an @reboot line and save.

> crontab -e -u irssi
crontab: no crontab for irssi - using an empty one
@reboot /usr/local/bin/screen -S irssi -md /usr/local/bin/irssi

The full paths to the executable files are specified, this is just a good habit as when you are dealing with startup scripts you don't know what environment you have. the '-S' flag labels the screen session for easier re-attachment later. The '-md' starts a new session and detaches it immediately.

Now, when the machine starts, irssi will be started as user irssi in a screen session named irssi that can be attached to with 'screen -R irssi'

[edit] Discussion

You don't really need a new user to do this, I just did it this way to isolate the program.

Gongo 03:47, 4 October 2007 (UTC)

Personal tools