• Blogs (9)
    • šŸ“± 236 - 992 - 3846

      šŸ“§ jxjwilliam@gmail.com

    • Version: ā€šŸš€ 1.1.0
  • Bash: auto launch some tools when reboot Unbuntu

    Blogs20122012-07-03


    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 &'