How to auto start a service on rebooting a linux machine?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rameshjumgam
    New Member
    • Dec 2010
    • 10

    How to auto start a service on rebooting a linux machine?

    I am having one shell script as a service in my project.
    It is auto starting in solaris but it is i don't know?

    The same shell script, i migrated to Linux. It is working in normal senario, but i have to do some changes to auto restart on rebooting Linux machine.

    My SOLARIS Environment:
    SunOS csdev-sf240-1 5.10 Generic_137111-08 sun4u sparc SUNW,Sun-Fire-V240

    My LINUX Environment:
    Linux lms-sfx4140-pc1 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

    ls /etc is below , please help with clear steps...,Thanks in advance..
    Code:
    a2ps.cfg               default               inittab.rpmorig   multipath_bindings        rc1.d              sudoers.16227
    a2ps-site.cfg          depmod.d              inputrc           multipath.conf            rc2.d              sudoers.19196
    acpi                   desktop-profiles      iproute2          multipath.conf.cisco      rc3.d              sudoers.19922
    adjtime                dev.d                 iscsi             multipath.conf.rpmorig    rc4.d              sudoers.22921
    aliases                dhcp6c.conf           issue             Muttrc                    rc5.d              sudoers.25288
    aliases.bak            DIR_COLORS            issue.net         Muttrc.local              rc6.d              sudoers.26292
    aliases.db             DIR_COLORS.xterm      issue.ssh         netplug                   rc.config.d        sudoers.28573
    alsa                   director.conf         java              netplug.d                 rc.d               sudoers.30137
    alternatives           dnsmasq.conf          jvm               NetworkManager            rc.local           sudoers.3182
    anacrontab             dnsmasq.d             jvm-commmon       nisp_domains              rc.sysinit         sudoers.6436
    asound.state           dumpdates             jwhois.conf       nscd.conf                 readahead.d        sudoers.9262
    at.deny                enscript.cfg          kde               nsswitch.conf             reader.conf        sudoers.9479
    audisp                 environment           kderc             nsswitch.conf.files       reader.conf.d      sudoers.9645
    audit                  esd.conf              kdump.conf        nsswitch.conf.nis         redhat-lsb         sysconfig
    auto.director          exports               kdump.conf.cisco  nsswitch.conf.nis-compat  redhat-release     sysctl.conf
    autofs_ldap_auth.conf  exports.mvfs          kdump_id_dsa      nsswitch.conf.nisplus     resolv.conf        syslog.conf
    auto.indirect          fb.modes              kdump_id_dsa.pub  nsswitch.conf.rpmorig     rmt                syslog_updater
    auto.indirect.m4       filesystems           krb5.conf         ntp                       rpc                system-profile
    auto.master            firmware              ksysguarddrc      ntp.conf                  rpm                system-profile.old
    auto.master.files      fonts                 ldap.conf         odbc.ini                  rwtab              system-profile.save
    auto.master.nis        foomatic              ld.so.cache       odbcinst.ini              rwtab.d            termcap
    auto.master.nisplus    fstab                 ld.so.conf        oddjob                    samba              udev
    auto.master.old        gconf                 ld.so.conf.d      oddjobd.conf              sane.d             updatedb.conf
    auto.master.rpmorig    gcrypt                lftp.conf         oddjobd.conf.d            sasl2              updatedb.conf.orig
    auto.misc              gdm                   libaudit.conf     openldap                  screenrc           vimrc
    auto.misc.cisco        ghostscript           libuser.conf      opt                       scrollkeeper.conf  vimrc.rpmsave
    auto.misc.rpmorig      gimp                  localtime         pam.d                     scsi_id.config     virc
    auto.net               gnome-vfs-2.0         login.defs        pam_pkcs11                securetty          warnquota.conf
    auto.smb               gnome-vfs-mime-magic  logrotate.conf    pam_smb.conf              security           wgetrc
    auto.ws                gpm-root.conf         logrotate.d       pango                     selinux            wpa_supplicant
    avahi                  gre.d                 lsb-release.d     passwd                    sensors.conf       X11
    bashrc                 group                 ltrace.conf       passwd-                   services           xdg
    blkid                  group-                lvm               pcmcia                    services.orig      xinetd.conf
    bluetooth              grub.conf             mail              pinforc                   sestatus.conf      xinetd.d
    bonobo-activation      gshadow               mailcap           pki                       setroubleshoot     xml
    cdrecord.conf          gssapi_mech.conf      mail.rc           pm                        setuptool.d        yp.conf
    cipe                   gtk-2.0               makedev.d         ppp                       sgml               yp.conf.prev
    conman.conf            hal                   man.config        prelink.cache             shadow             yum
    cron.d                 host.conf             maven             prelink.conf              shadow-            yum.conf
    cron.daily             hosts                 mgetty+sendfax    prelink.conf.d            shells             yum.repos.d
    cron.deny              hosts.allow           mime.types        printcap                  skel               zlogin
    cron.hourly            hosts.deny            minicom.users     profile                   slrn.rc            zlogout
    cron.monthly           hosts.orig            mke2fs.conf       profile.d                 smrsh              zprofile
    crontab                hp                    modprobe.conf     protocols                 snmp               zshenv
    cron.weekly            htdig                 modprobe.conf~    purple                    socks.conf         zshrc
    csh.cshrc              httpd                 modprobe.d        quotagrpadmins            sound
    csh.login              idmapd.conf           motd              quotatab                  ssh
    cups                   init.d                motd.BAK          racoon                    stunnel
    cvs-rpm                initlog.conf          mtab              rc                        sudoers
    dbus-1                 inittab               mtools.conf       rc0.d                     sudoers.13426

    Thanks in Advance...
    Last edited by Niheel; Mar 3 '11, 03:54 PM.
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    I would recommend putting the script to kick off your 'service' in the /etc/rc.d files (some flavors it's rc0.d, rc1.d, others it's /etc/init.d/ . If you post a 'ls /etc' we can help you determine exactly which one it is).

    You can either move your whole script there (not recommended) or create a script to kick off your script, such as below

    #!/bin/bash
    #script to start 'myscript' on boot

    ./usr/share/myscript

    #end
    and put that script in your init files in /etc/.

    You'll need to make it executable by root (chmod +x <files>), and then inside those init files, the ones with a capitol S are 'startup' scripts, so the above file would need to be called something like S88myscript-start, and be put in the right place in the /etc/ folders (in my case I would put it in /etc/rc3.d) to make sure the other things your script calls are already loaded.

    Comment

    Working...