Run bash script on startup in Linux Mint and open mate-terminal automatically
After a day of struggling I finally ended up with even better thing I needed:
#!/bin/bash
# Adds RVM to needed paths to start servers with needed Ruby version
PATH=$PATH:$HOME/.rvm/bin
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
# I need this server to run in background
startLocalRedmineServer()(
cd /home/adminuser/ruby_projects/redmine/
rails server webrick -e production --port 3001
)
# I need this to be done in background also
proxyLocalRedmineServer()(
proxylocal 3001 --host=mylocalredmine
)
# This thing should open mate-terminal, run start server, so that I can see real time logs, and stay on the screen in case I need it to be restarted
startOtherLocalServer()(
mate-terminal -e "bash -c 'cd /home/adminuser/ruby_projects/project_abc/';'rails s';'exec /bin/bash'"
)
# This thing should open mate-terminal and start proxying + remain opened
proxyOther()(
mate-terminal -e "bash -c 'proxylocal 3000 --host=projectabc'; 'exec /bin/bash'"
)
startLocalRedmineServer &
proxyLocalRedmineServer &
startOtherLocalServer &
proxyOther &
wait
This scripts is added for startup as I've written above in the question. After system starts this script adds new paths, which were lacking, and then starts 4 separate subprocesses. Two of them - that is Redmine server and its proxy - work in background (I do not need to stop them or change there anything). Two other functions open separate terminals, start local rails server and proxy it, so that I can stop it or restart when needed.
Related videos on Youtube
kovpack
Updated on September 18, 2022Comments
-
kovpack over 1 year
I'm new to Linux, so not sure how to do what I want.
I have
my_script.sh
(executable, of course) like this:#!/usr/bin/env bash mate-terminal -e "bash -c 'cd /home/my_user/ruby_projects/my_app/';'rails s';exec $SHELL"
NOTE: This script should open terminal, change current directory to the given one in that terminal, start rails application without closing terminal. All these things should be done after booting of the system automatically (now I run this script manually). Script contains a few similar comands, so a few terminals should be opened.
If I open terminal, go to the directory of the script, run
./my_script.sh
- everything works perfectly and exactly how I want it to work, but every time I boot I have to do this manually.So I went to Control center -> Startup Applications -> Add -> browsed my shell script, gave name -> Add
After that I restarted system and... :( Everything what I see is a few blinks on the screen (that is the opening and closing of mate-terminals) - everything happens so quickly that I can not see what it shows (however, all terminals should remain opened!). And, of course, no rails apps are started. All terminals are closed. How to fix this?
Update: at first my thought was that not all processes that were needed for rails apps started and that is why terminals simply closed, so I tried ty add
sleep 10
for the script to wait till everything boots properly, but that changed nothing - blinking was just delayed by 10 seconds.-
slm over 9 yearsWhere are you trying to get this to run? Upon reboots of the system? That's a special situation that you cannot simply add scripts like this and expect them to run. Especially with X GUI's such as
mate-terminal
. Please update your Q and describe what you're really trying to accomplish here. -
kovpack over 9 yearsIt's already written what I'm trying to accomplish. I've made it bold for you. Main task - run script automatically after each system boot, but not manually.
-
Leiaz over 9 yearsThis can't really be done "at boot". Perhaps you mean when your user logs into the Desktop ? If that "Control Center" is similar to the Ubuntu one, this question (and second answer) is relevant. And what will be the value of
$SHELL
here ? Because when I runbash -c "echo $SHELL"
I get zsh :) -
slm over 9 yearsKeep in mind that there is no X windows for
mate-terminal
to connect to if you're running this. If you're attempting to make your rails app start when the system boots you suppose to make a service around your Rails app which you can useservice myrailsapp start
or service myrailsapp stop` commands to to start/stop it. You can also control where it's logging and other things go as well from here. But this is a broad topic. -
kovpack over 9 yearsI've found the solution and added answer. It works perfectly :) Just a few things were needed - RVM & subprocesses.
-