Startup scripts in Mint 19.x

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Please don't add support questions to tutorials,start your own thread in the appropriate sub-forum instead. Before you post please read this
Post Reply
User avatar
catweazel
Level 18
Level 18
Posts: 8233
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Startup scripts in Mint 19.x

Post by catweazel » Sat Aug 11, 2018 11:45 pm

Objective
This tutorial shows you how to correctly implement a startup script in Mint 19.

Background
It used to be that you could implement a simple startup script in rc.local but that is now frowned upon. In addition, third party services that would start automatically under Mint 18.x will not necessarily automatically start under Mint 19.x.

To correctly implement a startup script you need to create a systemd unit (service, if you prefer).

About the example
I run hardware RAID using Adaptec 6805TQ cards (under $US50 brand new on FleaBay). Adaptec provide a browser-based storage manager (running on Apache Tomcat's Catalina servelet) that used to auto-start under Mint 18, but after installing and rebooting on Mint 19, the storage manager no longer auto-starts, hence the need for me to create a systemd unit to auto-start the web server. You can modify the example below quite easily for your own needs.

Prerequisites
All you need is the script to be run. In the example, I'm using /usr/StorMan/StorAgnt.sh but you can reference any script you like.

Step 1
Create the initial service definition:

sudo nano /etc/systemd/system/storage.service

Substitute your service name for storage in the above example.

Add the following text to the newly created file:

Code: Select all

[Unit]
After=network.target

[Service]
ExecStart=/usr/StorMan/StorAgnt.sh

[Install]
WantedBy=default.target
Use ctrl-o + Enter to save the file. Use ctrl-x to exit. Replace /usr/StorMan/StorAgnt.sh with the fully qualified path and name of your script.

In the example above:

After: Tells systemd when the script should be run. In this case, the script will run after the network has started.
ExecStart: Is the fully qualified path to the script you want to execute.
WantedBy: Specifies the boot target that your new systemd unit should be installed to.

See man systemd.service for more information.

Step 2
Set the execute permissions on your script:

sudo chmod 744 /usr/StorMan/StorAgnt.sh

See this link for information about chmod 774

Step 3
Change the access mode permissions of your service definition:

sudo chmod 664 /etc/systemd/system/storage.service

See this link for information about chmod 664

Step 4
Prepare systemd to run your service:

Code: Select all

sudo systemctl daemon-reload
sudo systemctl enable storage.service
At this point you should have a message to the effect:

Code: Select all

Created symlink from /etc/systemd/system/default.target.wants/storage.service to /etc/systemd/system/storage.service.
Step 5
Start the service:

sudo systemctl start storage.service

If all went well, your script has been executed. To test further, reboot your system.

That's all there is to it.
¡uʍop ǝpısdn sı buıɥʇʎɹǝʌǝ os ɐıןɐɹʇsnɐ ɯoɹɟ ɯ,ı

ugly
Level 3
Level 3
Posts: 192
Joined: Thu Nov 24, 2016 9:17 pm

Re: Startup scripts in Mint 19.x

Post by ugly » Sun Aug 12, 2018 12:30 am

Thanks for the helpful tutorial and additional information links.

I've been able to make a few startup scripts using systemd units.

I'm too new to Linux to understand why some people think systemd is the devil. In my, limited, experience, getting scripts to run at shutdown and startup using systemd was a lot easier and more reliable than making scripts in init.d and the various rc folders.

User avatar
catweazel
Level 18
Level 18
Posts: 8233
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: Startup scripts in Mint 19.x

Post by catweazel » Sun Aug 12, 2018 12:35 am

ugly wrote:
Sun Aug 12, 2018 12:30 am
Thanks for the helpful tutorial and additional information links.
You're most welcome.
ugly wrote:I've been able to make a few startup scripts using systemd units.

I'm too new to Linux to understand why some people think systemd is the devil. In my, limited, experience, getting scripts to run at shutdown and startup using systemd was a lot easier and more reliable than making scripts in init.d and the various rc folders.
Some linux purists despise systemd. This user puts it quite succinctly:
People hate systemd because it’s a pain in the ass to maintain, it’s complex, and defies the UNIX Philosophy. Which triggers UNIX purists, and it’s very heavy compared to other init systems such as OpenRC, and Runit.

On the grander scheme of things it’s simple for the user, but difficult for the developers. Despite it being implemented on the top popular distros (Debian, Ubuntu, Arch, OpenSUSE, Fedora, etc etc… On a relevant side-note, it’s not so secure like other init systems. As previously seen with Systemd’s vulnerability issues people have reported on.
https://forum.level1techs.com/t/whats-t ... d/119256/4
¡uʍop ǝpısdn sı buıɥʇʎɹǝʌǝ os ɐıןɐɹʇsnɐ ɯoɹɟ ɯ,ı

Ted3658
Level 1
Level 1
Posts: 13
Joined: Fri Jan 19, 2018 6:09 pm

Re: Startup scripts in Mint 19.x

Post by Ted3658 » Sat Dec 01, 2018 1:38 pm

Will this work if a script asks for a password?

I want to run a script at start up that asks for a pw, and I know I can't pipe in the pw, but I'd be happy if at start up it would automatically open terminal, run the script, and then just sit there at the pw prompt waiting for me to put in my pw.

Thanks.

george33
Level 1
Level 1
Posts: 28
Joined: Tue Jan 08, 2019 1:54 pm

Re: Startup scripts in Mint 19.x

Post by george33 » Tue Jan 08, 2019 2:03 pm

May be exist automate tools for all that boring steps? Just enter name of command file and name of service and the others can do the computer (tool). Or it is a rocket science on Linux? :) P. S. I newb in Linux and such issues too weird for me.

User avatar
BG405
Level 7
Level 7
Posts: 1688
Joined: Fri Mar 11, 2016 3:09 pm
Location: England

Re: Startup scripts in Mint 19.x

Post by BG405 » Sat Jan 12, 2019 4:22 pm

Thanks for posting this useful stuff Catweazel. Look forward to seeing you on here when you're back from your travels! :)
Dell Inspiron 1525 - LM17.3 CE 64-------------------Acer D255E 2GB - Manjaro KDE, LM17.3 KDE 32
Toshiba NB305 - Manjaro KDE------------------------K7S5A AMD 1.2GHz - LM17.3 Xfce 32 & WinXP-Pro
Acer Aspire E11 ES1-111M - LM18.2 KDE 64 ----Dell PII 350 64MB - Puppy 4.3 & Win98-SE

Namf_Mint
Level 1
Level 1
Posts: 12
Joined: Fri Apr 28, 2017 9:03 pm

Re: Startup scripts in Mint 19.x

Post by Namf_Mint » Sat Jan 12, 2019 10:36 pm

One can also run a script via Mint's 'Startup Applications' tool.

User avatar
BG405
Level 7
Level 7
Posts: 1688
Joined: Fri Mar 11, 2016 3:09 pm
Location: England

Re: Startup scripts in Mint 19.x

Post by BG405 » Sat Jan 12, 2019 11:49 pm

Namf_Mint wrote:
Sat Jan 12, 2019 10:36 pm
One can also run a script via Mint's 'Startup Applications' tool.
Indeed, but if I'm not mistaken, Catweazel's approach allows services etc. to be started in precise order and not just following set timeouts post login. :wink:
Dell Inspiron 1525 - LM17.3 CE 64-------------------Acer D255E 2GB - Manjaro KDE, LM17.3 KDE 32
Toshiba NB305 - Manjaro KDE------------------------K7S5A AMD 1.2GHz - LM17.3 Xfce 32 & WinXP-Pro
Acer Aspire E11 ES1-111M - LM18.2 KDE 64 ----Dell PII 350 64MB - Puppy 4.3 & Win98-SE

george33
Level 1
Level 1
Posts: 28
Joined: Tue Jan 08, 2019 1:54 pm

Re: Startup scripts in Mint 19.x

Post by george33 » Sun Jan 13, 2019 1:58 am

Namf_Mint wrote:
Sat Jan 12, 2019 10:36 pm
One can also run a script via Mint's 'Startup Applications' tool.
Yep it works even for services as has to be! Thanks!

User avatar
amendoza
Level 1
Level 1
Posts: 2
Joined: Thu Jan 31, 2019 4:56 pm

Re: Startup scripts in Mint 19.x

Post by amendoza » Fri Feb 01, 2019 5:48 am

Thanks a lot! Had been having some troubles with the anchor from unbound not functioning properly, so here it is the service config, modified with your steps, and unbound-anchor now properly executes after I have network online :D

[Unit]

Description=Restart unbound.service after network online, to help with the anchor bug. --By asomarriba

After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=/bin/systemctl restart unbound.service
StandardOutput=journal

[Install]
WantedBy=default.target

Post Reply

Return to “Tutorials”