Linux (unbuntu) start up scripts
Hi,
How do I get this working in unbuntu 11.xx?
I am the first to admit I am know Linux guru and have never played with automated start up scripts before. I am trying to get Dynimps to start with the OS, and run as a service/demon. But when I try the script below i get a (can't write to PID file) error, or the below
so the script is
Can any one point me in the right direction? I would really like to get this working as manualy starting all the servers after a reboot is pain. Also will a service/demon recover if it crashes, can it be made to check it is running and if not atempt to restart?
Cheers
Aaron
How do I get this working in unbuntu 11.xx?
I am the first to admit I am know Linux guru and have never played with automated start up scripts before. I am trying to get Dynimps to start with the OS, and run as a service/demon. But when I try the script below i get a (can't write to PID file) error, or the below
[EMAIL="aaron@ubuntu:/etc/init.d$"]aaron@ubuntu:/etc/init.d$[/EMAIL] dynamips start Cisco Router Simulation Platform (version 0.2.8-RC2-x86) Copyright (c) 2005-2007 Christophe Fillot. Build date: Jan 18 2011 19:22:29 Unable to create lock file "c7200_i0_lock". VM default: unable to create instance! C7200: unable to create instance!
so the script is
#!/bin/sh # Start/stop the dynamips program as a daemon. # ### BEGIN INIT INFO # Provides: dynamips # Default-Start: 2 3 4 5 95 # Default-Stop: 0 1 6 05 # Short-Description: Cisco Hardware Emulator daemon ### END INIT INFO NAME="dynamips" ALIES="dynamips" DAEMON=/usr/bin/$NAME PIDFILE=/var/run/$ALIES.pid PORT=7200 DESC="Cisco Hardware Emulator" SCRIPTNAME=/etc/init.d/$ALIES WORKDIR=/common/dynamips/$ALIES test -f $DAEMON || exit 0 . /lib/lsb/init-functions start() { log_daemon_msg "Starting $DESC: $ALIES" start-stop-daemon --start --chdir $WORKDIR --background --make-pidfile --pidfile $PIDFILE --name $NAME --startas $DAEMON -- -H $PORT -l /var/log/$ALIES.log log_end_msg $? } stop() { log_daemon_msg "Stopping $DESC: $ALIES" start-stop-daemon --stop --quiet --pidfile $PIDFILE --name $NAME log_end_msg $? } reload() { log_daemon_msg "Reloading $DESC: $ALIES" start-stop-daemon --stop --retry 5 --quiet --pidfile $PIDFILE --name $NAME start-stop-daemon --start --chdir $WORKDIR --background --make-pidfile --pidfile $PIDFILE --name $NAME --startas $DAEMON -- -H $PORT -l /var/log/$ALIES.log log_end_msg $? } status() { status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $? } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; reload) reload ;; status) status ;; *) log_action_msg "Usage: $SCRIPTNAME {start|stop|restart|status}" exit 2 esac exit 0
Can any one point me in the right direction? I would really like to get this working as manualy starting all the servers after a reboot is pain. Also will a service/demon recover if it crashes, can it be made to check it is running and if not atempt to restart?
Cheers
Aaron
- If you can't explain it simply, you don't understand it well enough. Albert Einstein
- An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
Linkin Profile - Blog: http://Devilwah.com
Comments
-
ChooseLife Member Posts: 941 ■■■■■■■□□□
Hi Aaron,
I've never used dynamips, but first thing catching my eye was that you're running an init.d script as a non-privileged used.
Try
aaron@ubuntu:/etc/init.d$ sudo dynamips start
instead.
If that works, you can make it start automatically by running
aaron@ubuntu:~$ sudo update-rc.d dynamips defaults“You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896
GetCertified4Less - discounted vouchers for certs -
DevilWAH Member Posts: 2,997 ■■■■■■■■□□
Perfect, thought I had tested that, dam you sudo. Need to go make a sandwich!
one last thing, in the script is has
WORKDIR=/common/dynamips/$ALIES
now this does not exist so I have to change it to make it work (easily done). But what would be the recommended place to point it to. I still a bit tied up with windows way of doing things so would be nice to get a Linux persons suggestion. What are the best practices for this? I mean in windows it would generally be the same as the install directory.- If you can't explain it simply, you don't understand it well enough. Albert Einstein
- An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
Linkin Profile - Blog: http://Devilwah.com -
ChooseLife Member Posts: 941 ■■■■■■■□□□
one last thing, in the script is has
WORKDIR=/common/dynamips/$ALIES
now this does not exist so I have to change it to make it work (easily done). But what would be the recommended place to point it to. I still a bit tied up with windows way of doing things so would be nice to get a Linux persons suggestion. What are the best practices for this? I mean in windows it would generally be the same as the install directory.
/usr/local/dynamips/ or /opt/dynamips (if this dir contains conf files, etc)
or
/var/lib/dynamips/ (if this dir contains runtime files)“You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896
GetCertified4Less - discounted vouchers for certs -
ChooseLife Member Posts: 941 ■■■■■■■□□□
Some more information on Linux filesystem hierarchy:
Basic and somewhat dated, but still 99% relevant:
Filesystem Hierarchy Standard
Ubuntu Manpage: hier - Description of the file system hierarchy
Recent changes (a bit more advanced):
filesystem - Why has /var/run been migrated to /run? - Ask Ubuntu - Stack Exchange“You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896
GetCertified4Less - discounted vouchers for certs -
DevilWAH Member Posts: 2,997 ■■■■■■■■□□
Cheers for those link, one day I will have time to really delve in to LINUX like it deservers. I take my hat of to you who understand it in depth.- If you can't explain it simply, you don't understand it well enough. Albert Einstein
- An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
Linkin Profile - Blog: http://Devilwah.com