Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Saturday, October 18, 2014

Back in Taiwan, after 4 years

It's been a long time since I abandon this blog and continue to write on my other blog ( which I also kinda abandon it as well when I discovered lots of new things on internet about this free CMS under google apps, which then leap me back to this blog ). My last post on this blog was in 2010, that was so 4 years a go, and where was I last 4 years ago ? Taiwan :). I remember landed here 4 years a go exactly at the same date, 19th October 2010. That was my very first international breakthrough integration projects. Yes, my first real international integration project on telecommunication industries if I may say so, because the previous one in 2007 did not actually a telecom project. It was mere an IT project where the company I work for was hired to build a web portal for an operator in Malaysia, but still, it's a web portal, it's IT, not Telecom :). First international project, alone, in a country where they don't use english on their daily live activities, what a combination. And also, that was my first year on ///, what experience do you expect from someone that just handling few telecom nodes with not-so-much experience ? Well, luckily for me, for that 2 months there, everything seem to go well. I got a lots of help from the local team, from my home base team, and also from prays that never stops from my family of course :) I learned a lots of new things, new techniques, new details that I never think of before. And what's better from all that ? I make new friends and new colleagues from around the globe. And now, 4 years later, I have moved to another country but still at the same company, and thankfully they still remember me, and invited me to come over again for another project. I really don't think this is fully because of my knowledge. I was a newbie 4 years a go, what knowledge and experience do you expect from that ? I believe this is more because of the relationship that I built with them for these past years. In Islam we call it Silaturahim, maintaining the relationship with everyone that has been worked with you. This is something I really learn from my past. I know I have let down some people by not finishing the projects they gave me when I was still in college. And I also remember some projects I couldn't finish during my first transition during the graduation and move to Jakarta. I still remember that all, and it will always be my reference to not do that again. ================ From Abu Hurayrah radi 'anhu, he said, "I heard the Prophet Sallallaahu' Alaihi Wa Sallam said, 'Whoever wants his sustenance expanded and their age extended , he shall maintain his relationship with his friends" (HR. Al-Bukhari no. 5986 and Muslim no. 2557).

Monday, April 5, 2010

Playing around with low end VPS box

Last week I just bought a VPS account for playing around with. It feels so great having our own shell account with root login so that we can do anything inside. I bought it from here. First of all, I bought the minimalist one, with 64mb memory, with no burstable ram :D, using Centos. I simply cant do anything, their Centos installation itself took around 20-30mb ram. I also not well enough playing with Yum. This is not great, so I upgraded the account to 128mb ram. At the same time I noticed that besides Centos, the hosting provider also provide Debian Lenny as the OS....why dont you said that from the beginning ??? :D Now, I'm running Lenny with 128mb ram. The VM specs itself it's not that bad, considering it's powered with 2 cpu @3Ghz, 128mb ram with no swap ( this guy here shares a great script to create a fake swap, but I dont need it any longer ;) read the rest of the entry to know why... ), and with 10Gb disk, more than enough storage for minimalist like me :)

So, first thing first, chop all the unnecessary program, replace it with the program with smaller 'cost'. Just do ps -ef and there I found apache2 and Sendmail sitting around and eating my memory. Just do :
# apt-get remove --purge sendmail apache2
And dont forget to kill them, and remove them from startup script.
# kill -9 pid
# update-rc.d -f remove apache2
# update-rc.d -f remove sendmail
Ok, that left me around 5 mb used memory. Not bad :)
Next thing is to replace the default shell, since bash shell become greedy enough to eat my memory. I replaced it with pdksh since after googling around, this pdksh shell saves ~1mb for every shell session...good enough. So I install it :
# apt-get install pdksh
Dont remove the bash shell yet, since it has a lot of dependencies. Leave it there, but dont use it :) How do we do that ? Just edit your own default shell to become pdksh in /etc/passwd :
# vi /etc/passwd
Change the line using /bin/bash, into /bin/pdksh, and voillaa, next login session will be using pdksh.
Not enought with just # prompt ? It's time to decorate your shell with some fancy prompts, just edit the .profile located inside the user's home directory ( just do ls -la to see it, since it's a hidden file ). Add the following line :
HOSTNAME=`hostname`
PS1=`print "\027\033[1;32m$USER@$HOSTNAME $PWD > \027\033[0m"`
And then do logout and login again, now you have a green fancy prompt sitting around in your shell prompts.

Next thing we can chop with, is the rsyslogd daemon and the sshd daemon. I got a great reference here. We will replace the rsyslogd daemon with syslog-ng, and replace the open-ssh server with dropbear.
# apt-get install syslog-ng && dpkg --purge rsyslog
And then the dropbear.
# touch /etc/ssh/sshd_not_to_be_run
# apt-get install dropbear
And edit the /etc/default/dropbear to set NO_START=0. To make sure of what we have change, just reboot the server.
And after fresh reboot, here's what I have in my VPS :

root@ath.cx /root > ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Apr05 ? 00:00:00 init [2]
root 340 1 0 Apr05 ? 00:00:00 /usr/sbin/syslog-ng -p /var/run/
root 348 1 0 Apr05 ? 00:00:00 /usr/sbin/dropbear -d /etc/dropb
root 367 1 0 Apr05 ? 00:00:00 /usr/sbin/xinetd -pidfile /var/r
root 382 1 0 Apr05 ? 00:00:00 /usr/sbin/cron
root 8864 348 0 02:24 ? 00:00:00 /usr/sbin/dropbear -d /etc/dropb
onty 8865 8864 0 02:24 pts/1 00:00:00 -pdksh
root 9192 8865 0 02:51 pts/1 00:00:00 -pdksh
root 9226 1 0 03:01 ? 00:00:00 nginx: master process /usr/sbin/
www-data 9227 9226 0 03:01 ? 00:00:00 nginx: worker process
root 9229 9192 0 03:01 pts/1 00:00:00 ps -ef

root@ath.cx /root > free -m
total used free shared buffers cached
Mem: 128 6 121 0 0 0
-/+ buffers/cache: 6 121
Swap: 0 0 0


Yep, I end up with just 6 mb ram for OS, dropbear, and nginx, and 121 ram free for my other apps.


Monday, May 18, 2009

Quick guide on UNIX task scheduling with at and batch command

While task scheduling in UNIX commonly uses Crontab facilities, UNIX based system (actually, Windows provide it too, at.exe) also provide at command. Both related to the same area, task scheduling. While Crontab aims to schedule a recurring command (every minutes, every month, every week, etc), at command aims to schedule a task that run once, with specific time arguments. Here’s one example of how we can schedule a task with at command:

$ at now + 1 hour <>&1 > outfile | mailx mygroup
!

commands will be executed using /bin/tcsh
job 1242637613.s at Mon May 18 16:06:53 2009

As we can see from the example above, we want to schedule a task to be executed 1 hour from now, and the task to be executed is diff file1 file2 2>&1 > outfile | mailx mygroup. The at command then returns the job id, which we will able to list all the queueing at command using atq or at –l below:

$ atq
Rank Execution Date Owner Job Queue Job Name
1st May 18, 2009 17:06 minsat 1242637774.a a stdin

$ at -l
1242637774.a Mon May 18 16:18:45 2009

From above we can see that there are only 1 jobs queuing at queue named ‘a’ (this is special queue name for at, and it is used to distinguish between the job executed by at and batch command). We can also see that the execution time will be May 18, 2009 17:06.

And to cancel the scheduled at command, we use atrm or at –r command as follows:

$ atrm 1242637774.a
1242637774.a: removed

$ at -r 1242637774.a
1242637774.a: removed

There are lots of other parameter we can use for describing the time parameter and how to execute the at command which is I found it quite ‘human readable’. Here’s some list of other possible parameter we can use:

1. Direct time
$ at 01.30
$ at 0815am Jan 24
$ at 5 pm FRIday
2. Now keyword
$ at now + 1 minutes
$ at now + 1 hours
$ at now "+ 1day"
3. Tomorrow keyword
$ at 0830 tomorrow
4. Noon keyword
$ at noon tomorrow
5. Midnight keyword
$ at midnight tomorrow
6. Week keyword
$ at 2pm next week
7. Piped with other command
$ echo "mail -s 'REMINDER: Task Scheduler samples' lintang.jp@gmail.com" | at '5/18/2009 10:00AM'
8. Putting the job inside a file
$ at –f runScript.sh now + 1 hour
9. Sending an email after the job is completed
$ at –m –f runScript.sh now + 1 hour
10. Using another shell instead of the user’s default shell for execution
$ at –c –f runScript.sh now + 1 week // C Shell
$ at –k –f runScript.sh now + 1 week // Korn Shell
$ at –s –f runScript.sh now + 1 week // Bourne Shell

Several behaviors and conditions that must be known when running at command as follows:

1. All environment variables, current working directory, file creation mask, and system resource limits during at utility execution will be retained and used when the at job is executed. So it’s different with Crontab where we have to set our environment variables manually to be called inside our script execution.
2. The default shell environment to be used during execution is the user’s default shell, listed in /etc/passwd.
3. Any users that is allowed or forbidden to use at command are listed in the following file :

1. /usr/lib/cron/at.deny // denied user
2. /usr/lib/cron/at.allow // allowed user

If the file does not exist, for example: at.allow file does not exist, means that all users are allowed to use at command.

While batch command is similar with at -q b -m now commands. Meaning that the batch command will use different queue with at (special queue named ‘b’), and by default it will send a report via email. It will also execute right away. If the queue is full, then the command will have to wait to be executed one by one.

Resource : 1. Unix at man pages, with some slang modifications :p

Fiuh, alhamdulillah, that was hard to wrote :D