I used to run several scripts at startup to set things the way I want my server running. After migrating to Ubuntu 18.04, I am having trouble with a few scripts and I am just wondering if this is still the preferred method to run shell scripts automatically after rebooting?

  • 2
    – muru
    Commented Jun 19, 2018 at 4:14
  • 1
    It depends. Best to properly configure your server so that you don't need any scripts. Second choice is to write a proper systemd script. We really can't advise you unless you post your scripts
    – Panther
    Commented Jun 19, 2018 at 6:28
  • I would make an entry in a runlevel. It is the recommended way.
    – abu_bua
    Commented Jun 30, 2018 at 13:06
  • @abu_bua "n recent versions of Linux systems such as RHEL 7, Ubuntu 16.04 LTS, the concept of runlevels has been replaced with systemd targets." (ostechnix.com/check-runlevel-linux)
    – jarno
    Commented Aug 27, 2019 at 7:37
  • @dsstorefile1 so what is the recommended way?
    – jarno
    Commented Aug 27, 2019 at 7:59

1 Answer 1


Following Ubuntu 16.04 traditional init startup scripts have been superseded by the systemd service and its configurations. Most of the scripts or script instructions were rewritten into so called systemd unit files. Therefore I would recommend to setup a systemd service for your custom startup scripts.

Create /etc/systemd/system/foo.service with content:

Description=Setup foo



Replace with your parameters accordingly. This service definition will run /opt/foo/setup-foo.sh on each startup.

Remember to load and enable the service:

sudo systemctl daemon-reload
sudo systemctl enable foo.service

For more info take a look at this example.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .