Home Forums Software InstaDMG Setting launchd dependancy for first time run script

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #376888
    generic_penguin
    Participant

    I am looking for a way for a launchd item to run at login window but prior to user authenticated

    I have read http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man5/launchd.plist.5.html
    And believe I need to be looking at a socket. But just don’t know what one

    What I wanted to achieve as a launchd item that at first boot would set the computer name to serial of machine and then do all the updates from the server

    Easy enough, But the thing I thought would be good would be to lock the desktop screen while this happens for end user netboot deployment’s so the end user can not login to the machine while updates are in progress.

    I came up with this idea

    Utilize the inbuilt ARD client function

    So script would be as follows

    #!/bin/sh

    open /System/Library/CoreServices/RemoteManagement/AppleVNCServer.bundle/Contents/Support/LockScreen.app

    say “setting computer name”

    SerialNumber=`/usr/sbin/system_profiler SPHardwareDataType |awk ‘/Serial/ { print $NF }’`

    if [ -z “$SerialNumber” ]; then
    echo “Logic board has been changed and no serial number found”
    SerialNumber=”BASESOE-“`date “+%Y%m%d”`
    /usr/sbin/scutil –set ComputerName “$SerialNumber”
    /usr/sbin/scutil –set LocalHostName “$SerialNumber”
    else
    echo “Setting Computer name and Local Host Name to $SerialNumber”
    /usr/sbin/scutil –set ComputerName “$SerialNumber”
    /usr/sbin/scutil –set LocalHostName “$SerialNumber”
    fi

    say “updating software”

    softwareupdate -i -a

    killall LockScreen

    say “rebooting computer”

    reboot

    # Destroy this script!
    srm “$0”

    So nice and simple building block above and works. The catch is when I launch with launchd it loads script prior to login window and

    “open /System/Library/CoreServices/RemoteManagement/AppleVNCServer.bundle/Contents/Support/LockScreen.app”

    will not lock screen in time

    I am looking for anyone who may have come across this before and can set a dependancy on login window launching first etc..

    Have tried the following with no success.. Any suggestions would be great.



    Disabled
    KeepAlive
    Label
    com.domain.firstime
    ProgramArguments

    /usr/sbin/runfirsttime.sh

    QueueDirectories

    RunAtLoad
    WatchPaths

    LimitLoadToSessionType

    LoginWindow

    #376889
    thomasb
    Participant

    Where have you put your launchd file?

    I think you need to make a LaunchAgent (put your plist file into /Library/LaunchAgents/, with root:wheel 644 permissions), to be able to use the [b]LimitLoadToSessionType[/b] key.

    [url]http://devworld.apple.com/technotes/tn2005/tn2083.html#SECLAUNCHDAGENT[/url]

    [quote][u]Quote: Apple[/u][p]”If you set LimitLoadToSessionType to an array, be aware that each instance of your agent runs independently. For example, if you set up your agent to run in LoginWindow and Aqua, the system will first run an instance of your agent in the loginwindow context. When a user logs in, that instance will be terminated and a second instance will launch in the standard GUI context.

    Finally, there are some significant gotchas associated with developing a pre-login launchd agent; see Sample Code ‘PreLoginAgents’ for more information.“[/p][/quote]

    [b]/Library/LaunchAgents/com.company.example.plist[/b]
    [code]

    Label
    com.company.example
    LimitLoadToSessionType

    LoginWindow

    ProgramArguments

    /path/to/your/script

    RunAtLoad
    [/code]

    #376892
    Greg Neagle
    Participant

    I agree with ThomasB’s recommendation about using a LaunchAgent that runs in the LoginWindow context. One more thing – after your script runs, instead of deleting itself, it should either delete the launchd plist that causes it to run, or sets the disabled flag to true. If you delete the script, but leave the launchd item is place, you’ll see launchd complaining in the system.log, since it’s being told to run a script that no longer exists.

    -Greg

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Comments are closed