`
roddy
  • 浏览: 17014 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

How to start a program automatic

阅读更多

Reference URL: http://unix.stackexchange.com/questions/20357/how-can-i-make-a-script-in-etc-init-d-start-at-boot

試過 It's work.

注意Script 内容格式,按下面写,如果发现not work 就检查script是否有错。名字可不加.sh, 如:tomcat都ok

 

 If you are on a Red Hat based system, as you mentioned, you can do the following:

  1. Create a script and place in /etc/init.d (e.g /etc/init.d/myscript). The script should have the following format:
#!/bin/bash# chkconfig: 2345 20 80# description: Description comes here....# Source function library../etc/init.d/functions

start(){# code to start app comes here # example: daemon program_name &}

stop(){# code to stop app comes here # example: killproc program_name}case"$1"in 
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    status)# code to check status of app comes here # example: status program_name;;*)
       echo "Usage: $0 {start|stop|status|restart}"esac

exit 0

The format is pretty standard and you can view existing scripts in /etc/init.d. You can then use the script like so /etc/init.d/myscript start or chkconfig myscript start. The ckconfig man page explains the header of the script:

 > This says that the script should be started in levels 2,  3,  4, and
 > 5, that its start priority should be 20, and that its stop priority
 > should be 80.

The example start, stop and status code uses helper functions defined in /etc/init.d/functions

  1. Enable the script

    $ chkconfig --add myscript 
    $ chkconfig --level 2345 myscript on 
    
  2. Check the script is indeed enabled - you should see "on" for the levels you selected.

    $ chkconfig --list | grep myscript
    

Hope this is what you were looking for.

分享到:
评论

相关推荐

    S7-200 Get Start Advanced en

    and how to create control programs for basic automatic tasks. After working through this manual, you will find it easy to solve typical controller tasks on your own. You can find and load the SIMATIC ...

    VB编程资源大全(英文源码 其它)

    cube.zip This example demonstrates how to rotate a cube in visual basic.<END><br>17 , sprite1.zip This is an Excellent example on how to use sprites in your program.<END><br>18 , charcreate.zip...

    2008年6月大学英语六级A卷真题

    certified new part.” She predicts that within 5 to 10 years fingers and toes will be regrown and limbs will start to be regrown a few years later. Repairs to the nervous system will start with optic ...

    Object- Oriented Programming with Ansi-C

    and how we harness generality and program to catch mistakes earlier. Along the way we encounter all the jargon — classes, inheritance, instances, linkage, methods, objects, polymorphisms, and more —...

    LCTF软件备份VariSpec™ Liquid Crystal Tunable Filters

    Now, a message box is posted to indicate that a filter was found, and the program checks whether initialization is complete, at 1 second intervals. When the filter is done initializing, the VsGui ...

    C# Game Programming Cookbook for Unity 3D - 2014

    4.3.1 A Simple Spawn Controller..................................49 4.3.1.1 Script Breakdown................................52 4.3.2 Trigger Spawner...........................................56 4.3.3 ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    How can we use a class Foo in a header file without access to its definition? We can declare data members of type Foo* or Foo&. We can declare (but not define) functions with arguments, and/or ...

    Visual C++ 编程资源大全(英文源码 其它)

    demo.zip How to send debugging output to a console in a MFC application(12KB)<END><br>56,statuslog.zip A very simple text logger that allows you to use printf-type formatting, with automatic ...

    Senfore_DragDrop_v4.1

    would be a good idea to have a quick look at the demos. The library has been completely rewritten and a lot of new features has been added. ------------------------------------------- 4. Known ...

    BCGControlBarPro.v12.00

    Just call CBCGPRibbonComboBox::EnableCalculator method to assign a calculator to the ribbon combobox. Override a new 'OnCalculatorUserCommand' method to implement your calculator commands. Please ...

    Professional C# 3rd Edition

    Before We Start 30 Our First C# Program 30 The Code 30 Compiling and Running the Program 31 Contents A Closer Look 31 Variables 34 Initialization of Variables 34 Variable Scope 35 Constants 38 ...

    一个win32下的ARM开源编译器

    There are a few restrictions how the ARM instruction set is implemented. The changes are minor and mostly have a minor impact. For the most part the basic instruction outline is the same. Where ...

    VB.NET Developer's Guide(4574).pdf

    Exercise 7.2 Adding a Menu to a Form at Design Time 323 Creating Dialog Boxes 1.Create a form. 2.Set the BorderStyle property of the form to FixedDialog. 3.Set the ControlBox, MinimizeBox, and ...

    STG (SNMP Traffic Grapher)

    then program writes collected data to specified file. Log file is comma separated. Here is format: First line is the header line : Program name: File creation time,Target Address,Community string,...

    DebuggingWithGDB 6.8-2008

    4.11 Setting a Bookmark to Return to Later . . . . . . . . . . . . . . . . . . . . . 4.11.1 A Non-obvious Benefit of Using Checkpoints . . . . . . . . . . . . 5 25 26 28 28 29 29 30 31 31 34 36 37 ...

    SAP屠夫作品汇总

    1.How to Activate Direct Posting to G/L Accounts and Material Account 605 2.What will Happen? 607 3.Mark delv. Completed 607 物料移动类型和后勤自动科目设置 608 分割评估和混合成本 620 业务背景: 620 ...

    python3.6.5参考手册 chm

    PEP 523: Adding a frame evaluation API to CPython PYTHONMALLOC environment variable DTrace and SystemTap probing support Other Language Changes New Modules secrets Improved Modules array ast ...

    操作系统(内存管理)

    /* This is the same as current_location, but cast to a * memory_control_block */ struct mem_control_block *current_location_mcb; /* This is the memory location we will return. It will * be ...

Global site tag (gtag.js) - Google Analytics