RUNLEVEL variable not set

Jeff Hanson jhansonxi at gmail.com
Fri Dec 24 18:58:09 UTC 2010


On Fri, Dec 24, 2010 at 8:36 AM, Scott James Remnant <scott at netsplit.com> wrote:
> The RUNLEVEL environment variable will be set in any job started by
> the "runlevel" event.
>
> Without seeing your job, I can't advise further, please feel free to
> follow up and attach the configuration you're having difficulty with.
>

I think I found the problem.  I overlooked the need to env RUNLEVEL.
I also had a problem with the syntax of the start stanza.

The config, rootlock, is below.  I would like your opinion of it even
though it is EVIL.  Being a fix for bug #21994 probably won't help
either.

# rootlock
# This sets the root password to that of the first member of the
# admin group in runlevel S (recovery-mode) to prevent unchallenged root
# access.  It disables the root password in every other runlevel.
# Copyright 2010 Jeff D. Hanson (jhansonxi at gmail.com)

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

description	"Set root account password in recovery-mode only"
author		"Jeff D. Hanson <jhansonxi at gmail.com>"

start on	runlevel [2345S]
env RUNLEVEL
task
script
        if [ "$RUNLEVEL" = "S" ] || [ "$RUNLEVEL" = "s" ]
        then
	    # Set root password to first admin member password
	    admin_name=$(grep -E '^admin:' /etc/group | sed -n
's/^\([^:]\+:[^:]\+:[^:]\+:\)\([^,]\+\)\(.*\)$/\2/p')
	    admin_pw=$(grep -E "^$admin_name:" /etc/shadow|cut -d: -f2|sed
's/\//\\\//g')
	    sed -i "s/^\(root:\)\([^:]\+\)\(:.*\)$/\1$admin_pw\3/" /etc/shadow
	    unset admin_pw
	else
	    # Disable root password
	    sed -i 's/^\(root:\)\([^:]\+\)\(:.*\)$/\1*\3/' /etc/shadow
	fi
end script



More information about the upstart-devel mailing list