running Startup scripts as root

Discussion in 'Mac Help/Tips' started by evildead, Mar 24, 2002.

  1. evildead macrumors 65816

    evildead

    Joined:
    Jun 18, 2001
    Location:
    WestCost, USA
    #1
    any one know how to run shell schipts as root at bootup? I know how to do it in Solaris but i dont know that much about BDS or OS X and how that stuff works.

    Thanks

    evildead
     
  2. crassusad44 macrumors 6502a

    Joined:
    Nov 30, 2001
    Location:
    Scandinavia
    #2
    Don't not *nix about Unix, but...

    ...you could try Apple key + S during startup, and you will boot straight into BSD, from where you can run different Unix apps that you have installed (shell, scripts, whatever)....

    You may need to use that su command...
     
  3. Taft macrumors 65816

    Taft

    Joined:
    Jan 31, 2002
    Location:
    Chicago
    #3
    Startup files.

    There are a variety of startup files that might suit your needs. Really it depends on what your doing.

    1) For most user-oriented processes, setting the set-user bit on the files permissions will suffice. In this case, you'll want to set the file as owned by root and then change its permissions to run the file as the file's owner. Like this:

    %chown root theProgram
    %chmod 4755 theProgram

    The 4 says that anyone can execute the file and anyone doing so will do it as root. This is a potential security risk. Make sure the program can't do anything malicious. If it can, then setup a group and make it executable only by people in the group (4750).

    Finally, change your .login file to execute the program at startup. cd to ~. Then type 'pico .login' and put the path and filename into the file so it looks like this:

    /myLocation/subFolder/theProgram

    2) For system level processes, you'll need to edit startup files. For instance, the /etc/rc file executes a bunch of commands that mount filesystems, setup virtual memory systems, etc. You can edit this to startup your own items, but only do so if you know what you are doing.

    There are many of these type of files each accessed at different points in startup for different purposes. Many services and deamons are started in this fashion. You can cripple your system by editing these files, so don't do it without knowing what you're up to.

    Matthew
     
  4. evildead thread starter macrumors 65816

    evildead

    Joined:
    Jun 18, 2001
    Location:
    WestCost, USA
    #4
    re: mrtrumbe

    Thanks for the imput. I was hoping it was as simple as it is in Solaris and I would just need to put the script in one of the cr. directories. I didnt want to edit system files if I could avoid it.

    I descied not to run it at boot ayway.. it might cause problems... im not really sure what kind of things it might do.

    this is what I want to run:

    #!/bin/sh
    #
    #
    # this kills hardware checksumming at startup

    sysctl -w net.link.ether.inet.apple_hwcksum_rx=0
    sysctl -w net.link.ether.inet.apple_hwcksum_tx=


    I need it to get my Cisco VPN client to work. I got the commands off the cisco site.
     
  5. macktheknife macrumors 6502a

    macktheknife

    Joined:
    Jan 24, 2002
    #5
    I'm not sure if this is the place to ask, but it sounds like you guys know what you're talking about. Anyhow, I'm trying to edit some scripts that will start jboss up automatically when I turn on my computer. I am also curious as to how to set a path so that when I type something like "jboss" in Terminal the program will start. I installed a script for MySQL and I've been able to get MySQL started in such a manner.

    I'd appreciate the assistance.
     
  6. macktheknife macrumors 6502a

    macktheknife

    Joined:
    Jan 24, 2002
    #6
    Found my answer

    I found this on Apple's Developers Website. This is just for anyone who needs to start their JBoss server (or almost any type of program for that matter) in the future.

    (Note it assumes a particular JBoss location /Library/JBoss --edit to suit your install)

    Put these in /Library/StartupItems/JBoss/

    #Begin File /Library/StartupItems/JBoss/JBoss
    #!/bin/sh

    . /etc/rc.common

    ##
    # Start J2EE App server
    ##

    StartService()
    {
    if [ "${JBOSS:=-NO-}" = "-YES-" ]; then
    ConsoleMessage "Starting JBoss"
    cd /Library/JBoss
    ./bin/run.sh > /var/log/jboss.log &
    fi
    }

    StopService()
    {
    cd /Library/JBoss
    ./bin/shutdown.sh > /var/log/jboss.log &
    }

    RestartService()
    {
    if [ "${JBOSS:=-NO-}" = "-YES-" ]; then

    ConsoleMessage "Retarting JBoss"
    cd /Library/JBoss
    ./bin/shutdown.sh > /var/log/jboss.log &
    ./bin/run.sh > /var/log/jboss.log &
    else
    cd /Library/JBoss
    ./bin/shutdown.sh > /var/log/jboss.log &
    fi
    }

    RunService "$1"
    #End File /Library/StartupItems/JBoss/JBoss

    #Begin File /Library/StartupItems/JBoss/StartupParameters.plist
    {
    Description = "JBoss App Server";
    Provides = ("JBoss");
    Requires = ("Resolver");
    Preference = "Late";
    Messages =
    {
    start = "Starting JBoss";
    stop = "Stopping JBoss";
    };
    }
    #End file /Library/StartupItems/JBoss/StartupParameters.plist


    edit your /etc/hostconfig to have a line:
    JBOSS=-YES-

    chmod +x the JBoss file in the StartupItems

    the jboss output is put in /var/log/jboss.log which can be viewed by
    opening it in console.app.
     

Share This Page