William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

Bash: auto launch some tools when reboot Unbuntu

Bash: auto launch some tools when reboot Unbuntu

In Unbuntu, you can always setup your tools / daemons to backend start/re-start/stop by default in /etc/rc.d/. That means for all login users, all these daemons are available.
However, sometimes we need some tools/daemons only available to some certain user: this user will start tools/daemon when he is login, so the tools/daemons are only used by him, not others. e.g., a tool like webstorm, or a testing DB like mongodb only used by login user ‘developer’.

In such case, we just need to setup user developer’s $HOME/.profile file (notice: not $HOME/.bashrc file). They are different: $HOME/.profile runs only one-time when the user login, while $HOME/.bashrc runs many times when he spawns terminitors. Here I gave an example to auto start webstrom GUI tool when user login.
in $HOME/.profile:

# 1. start webstorm
ps -ef | grep webstorm | grep -v grep >/dev/null 2>&1
if [ $? -ne 0 ]; then
  cd $HOME/WebStorm-117.501/bin/; ./webstorm.sh &
fi

It seems enough: when user logins, the script checks if webstorm GUI running or not, if not, start it; else do nothing.
By the way, you can alwasy add alias in $HOME/.bashrc: The following I provide a shortcut to start webstorm GUI manually by using ‘alias’
in $HOME/.bashrc:

alias webstorm='cd $HOME/apps/WebStorm-117.501/bin/; ./webstorm.sh &'
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: