Announcement

Collapse
No announcement yet.

FAQ: Autostart / Autorun, Periodic run

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    FAQ: Autostart / Autorun, Periodic run

    Starting/stopping things when the system is starting or shutting down.


    > Upstart
    Upstart is an event-based replacement for the /sbin/init daemon which handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running...
    Few sublinks:
    > Getting Started
    > Upstart Intro, Cookbook and Best Practices
    > FAQ

    > Upstart Development Blog


    "These are not really standards"
    (but they are good suggestions)

    > freedesktop.org
    > Specifications
    > Desktop Entry Specification
    > Autostart Specification


    KDE

    > Autostart
    > Chapter 4. Autostarting Applications and Run-Once Applications
    > Aaron Seigo: autostarting apps in kde4


    Autostart places:
    • /etc/xdg/autostart/
    • /usr/share/autostart/
    • ~/.config/autostart/
    • ~/.kde/Autostart/



    "Hooking"

    User application could be started from the existing scrip. One script is the > /etc/kde4/kdm/Xsetup:
    Both KDM and GDM have startup scripts that are executed when X is initiated. For GDM, these are in /etc/gdm/ , while for KDM this is done at /etc/kde4/kdm/Xsetup. In either case, you can paste in an xrandr command line string into one of these scripts...
    Earlier > Topic: Capturing the images of the ksplash & kdm & ksplash again. It is using the Xsetup hook to capture the boot screens.


    Periodically running things.

    Cron

    > CronHowto

    With the KDE gui:
    > Task Scheduler

    System Task Scheduler:
    Code:
    KRunner: Alt + F2 and kdesudo kcmshell4 kcm_cron
    Earlier > Topic: KDE Control Module


    Anacron

    > Anacron wiki

    man anacron:
    NAME
    anacron - runs commands periodically

    SYNOPSIS
    anacron [-s] [-f] [-n] [-d] [-q] [-t anacrontab] [-S spooldir] [job] ...
    anacron [-S spooldir] -u [-t anacrontab] [job] ...
    anacron [-V|-h]
    anacron -T [-t anacrontab]

    DESCRIPTION
    Anacron can be used to execute commands periodically, with a frequency specified in days. Unlike
    cron( 8 ), it does not assume that the machine is running continuously. Hence, it can be used on
    machines that aren't running 24 hours a day, to control daily, weekly, and monthly jobs that are
    usually controlled by cron.

    When executed, Anacron reads a list of jobs from a configuration file, normally /etc/anacrontab
    (see anacrontab(5)). This file contains the list of jobs that Anacron controls. Each job entry
    specifies a period in days, a delay in minutes, a unique job identifier, and a shell command...

    Using anacron:
    1) Simply put executable script file in the /etc/cron.daily, /etc/cron.weekly or /etc/cron.monthly.
    2) Touch the script file:
    Code:
    sudo touch /etc/cron.daily/scriptfile
    (cron.daily if it is a daily job)

    Testing anacron:
    Code:
    sudo anacron -f -d
    man anacron:
    -f Force execution of the jobs, ignoring the timestamps.
    -d Don’t fork to the background. In this mode, Anacron will output
    informational messages to standard error, as well as to syslog.
    The output of jobs is mailed as usual.
    Anacron messages in the log:
    Code:
    grep anacron /var/log/syslog
    Anacron keeps timestamps in the /var/spool/anacron/. If you remove cron.daily, cron.weekly or cron.monthly files from there, anacron will execute daily, weekly or monthly scripts at the next startup.
    A good place to start: Topic: Top 20 Kubuntu FAQs & Answers
    Searching FAQ's: Google Search 'FAQ from Kubuntuforums'

    #2
    Re: FAQ: Autostart / Autorun, Periodic run

    Examples


    With the Upstart

    As default the Upstart is having the root /1/ rights.

    Making upstart job to
    - make a directory.
    - run an application (showfsck /2/) that needs the root rights.
    - directing the application output to the file.


    Making /etc/init/fsck-list.conf:
    description "showfsck output to file"


    start on started kdm


    script

    mkdir -p /tmp/fsck-output/
    echo "Upstarting the showfsc" > /tmp/fsck-output/showfsck.txt
    showfsck >> /tmp/fsck-output/showfsck.txt

    end script
    After the boot the /tmp/fsck-output/showfsck.txt has:
    Upstarting the showfsc
    14/34 mount(s) until fsck for /dev/disk/by-uuid/81cbc603-629b-415a-a21d-0f9b152e2b2a
    ***************************
    * 4 * /24 mount(s) until fsck for /dev/sdc2
    ***************************
    17/32 mount(s) until fsck for /dev/sdc5
    19/33 mount(s) until fsck for /dev/sdc6
    25/36 mount(s) until fsck for /dev/sdd3
    27/37 mount(s) until fsck for /dev/sdd4

    With the "Hooking"

    Making a bash script, /usr/local/bin/fsck-list.sh:
    Code:
    #!/bin/bash
    
    mkdir -p /tmp/fsck-output/
    echo "Hooked" > /tmp/fsck-output/showfsck.txt
    showfsck >> /tmp/fsck-output/showfsck.txt
    Adding the script call to the /etc/kde4/kdm/Xsetup:
    Code:
    #! /bin/sh
    # Xsetup - run as root before the login dialog appears
    
    #xconsole -geometry 480x130-0-0 -notify -verbose -fn fixed -exitOnFail -file /dev/xconsole &
    
    # Call the /usr/local/bin/fsck-list.sh
    /usr/local/bin/fsck-list.sh &
    
    /sbin/initctl -q emit login-session-start DISPLAY_MANAGER=kdm
    After the boot the /tmp/fsck-output/showfsck.txt has:
    Hooked
    11/34 mount(s) until fsck for /dev/disk/by-uuid/81cbc603-629b-415a-a21d-0f9b152e2b2a
    ***************************
    ***************************
    * fsck at next mount for /dev/sda2
    ***************************
    ***************************
    14/32 mount(s) until fsck for /dev/sda5
    16/33 mount(s) until fsck for /dev/sda6
    22/36 mount(s) until fsck for /dev/sdb3
    24/37 mount(s) until fsck for /dev/sdb4

    User's Autostart

    System Settings > Startup and Shutdown

    If you don't mind to type the password you could use the kdesudo /3/.

    Making a script file /usr/local/bin/fsck-list.sh:
    Code:
    #!/bin/bash
    
    mkdir -p /tmp/fsck-output/
    echo "Kdesudoing the showfsck" > /tmp/fsck-output/showfsck.txt
    kdesudo bash -c "showfsck >> /tmp/fsck-output/showfsck.txt"
    and adding it to the KDE startup list.

    [img width=400 height=217]http://img24.imageshack.us/img24/2535/addautostartscript.jpg[/img]

    The KDE desktop is now asking the password to execute the "showfsck >> /tmp/fsck-output/showfsck.txt".

    [img width=400 height=210]http://img121.imageshack.us/img121/9598/passwordquery.jpg[/img]

    After this the /tmp/fsck-output/showfsck.txt has:
    Kdesudoing the showfsck
    10/34 mount(s) until fsck for /dev/disk/by-uuid/81cbc603-629b-415a-a21d-0f9b152e2b2a
    24/24 mount(s) until fsck for /dev/sda2
    13/32 mount(s) until fsck for /dev/sda5
    15/33 mount(s) until fsck for /dev/sda6
    21/36 mount(s) until fsck for /dev/sdb3
    23/37 mount(s) until fsck for /dev/sdb4

    With the sudeoers

    Changing the rights with the sudoers /4/ but using the sudoers.d /5/.

    Adding an exeption:
    Code:
    sudo visudo -f /etc/sudoers.d/01_exception
    Inserting:
    Code:
    rog ALL= NOPASSWD:/usr/sbin/showfsck
    Save and exit.

    Making a script file /usr/local/bin/fsck-list.sh:
    Code:
    #!/bin/bash
    
    mkdir -p /tmp/fsck-output/
    echo "Rights to Rog" > /tmp/fsck-output/showfsck.txt
    sudo /usr/sbin/showfsck >> /tmp/fsck-output/showfsck.txt
    and adding it to the KDE startup list.

    [img width=400 height=232]http://img121.imageshack.us/img121/3148/autostartsriptsudo.jpg[/img]

    After the reboot the /tmp/fsck-output/showfsck.txt has:
    Rights to Rog
    ***************************
    * 4 * /34 mount(s) until fsck for /dev/disk/by-uuid/81cbc603-629b-415a-a21d-0f9b152e2b2a
    ***************************
    18/24 mount(s) until fsck for /dev/sda2
    7/32 mount(s) until fsck for /dev/sda5
    9/33 mount(s) until fsck for /dev/sda6
    15/36 mount(s) until fsck for /dev/sdb3
    17/37 mount(s) until fsck for /dev/sdb4

    /1/ > Rootsudo

    /2/ Package: showfsck, man showfsck:
    showfsck - Show the number of reboots until a forced fsck

    With the Natty the showfsck needs the root /1/ rights:
    :~$ showfsck
    Unable to access information for /dev/disk/by-uuid/81cbc603-629b-415a-a21d-0f9b152e2b2a
    Unable to access information for /dev/sdc2
    Unable to access information for /dev/sdc5
    Unable to access information for /dev/sdc6
    Unable to access information for /dev/sdd2
    Unable to access information for /dev/sdd3
    Unable to access information for /dev/sdd4
    /3/ > Redirect output as sudo

    /4/ > Sudoers

    /5/ > /etc/sudoers.d/ (and all those d directories)
    A good place to start: Topic: Top 20 Kubuntu FAQs & Answers
    Searching FAQ's: Google Search 'FAQ from Kubuntuforums'

    Comment

    Working...
    X