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 17
Level 17
Posts: 7122
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: 161
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 17
Level 17
Posts: 7122
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ɹɟ ɯ,ı

Post Reply

Return to “Tutorials”