Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running bash script in upstart .conf script

I would like run my bash script (kvm_manage) in startup, and it doesnt work. Here is my upstart .conf script:

      description "kvm start skript"

      start on local-filesystem
      stop on shutdown

      respawn 

      script
         exec /etc/kvm_manage start
      end script

I want run it with argument "start". It is possible? What should I change?

thanks for help

like image 389
Joffo Avatar asked Dec 10 '13 17:12

Joffo


People also ask

What are Linux startup scripts and how to use them?

Linux startup scripts are tools or programs that are run by the kernel each time your system restarts. Users can leverage various Linux startup commands to configure programs or run certain tasks once the system has booted. Luckily, there are several ways to auto-execute startup scripts in Linux.

How do I configure startup commands in Linux?

You can configure startup commands in several ways. We will demonstrate the use of Linux CRON jobs and init tasks for running scripts at startup. We will also show you how to do this using Upstart. CRON is a simple but powerful job scheduler that can run certain tasks at system reboot. We can easily create a startup job using CRON.

What is the best way to execute a script at startup?

In this article, we took a look at different ways of executing a script at startup in Linux. Each one of them has its pros and cons, but generally speaking, systemd and cron should be preferred when available. Meanwhile, rc.local and init.d can be used as fallbacks.

How do I run a script at reboot in Linux?

This is usually the case for most Linux distributions. And, if your script uses environment variables, you must include those at your crontab. One simple method of running jobs at reboot is to place them in the /etc.init.d directory. But first, make sure the script is executable.


1 Answers

Running a command via exec with arguments is fine - see http://upstart.ubuntu.com/wiki/Stanzas#exec which gives such an example.

However, upstart will use /bin/sh not bash, so if your script needs bash you'd need something like

script
    exec bash -c '/etc/kvm_manage start'
end script

Update: See also the suggestion in the comments from Guss to use the exec stanza instead for simple cases:

exec bash -c '/etc/kvm_manage start'

Or if kvm_manage is an executable with a she-bang (#!/bin/bash), then simply:

exec /etc/kvm_manage start
like image 85
DNA Avatar answered Oct 30 '22 03:10

DNA