I am running a web server on an AWS EC2 micro instance. The instance has ~630MB of RAM. With time, I have several httpd processes and very little free RAM. When I restart the httpd service, I end up freeing about 350MB of RAM.
I thought of having this automated every 12 hours using a cron job under root. My script includes code as
service httpd restart service mysqld restart ps aux free -m
This is the first time I am attempting cron scripts.
I receive an email with the expected output for
ps aux and
free -m, but
./scriptName.sh: line 1: service: command not found ./scriptName.sh: line 2: service: command not found
for the restarts commands.
The script did run as root. I am afraid that using
sudo may cause the script to hang. The relevant lines from the output of
root 14664 0.0 0.2 142200 1720 ? S 22:41 0:00 CROND root 14665 0.0 0.2 9296 1236 ? Ss 22:41 0:00 /bin/sh -c ./scriptName.sh smmsp 14667 0.0 0.6 76020 4244 ? R 22:41 0:00 /usr/sbin/sendmail -FCronDaemon -i -odi -oem -oi -t -f root root 14669 0.0 0.1 11244 1008 ? R 22:41 0:00 ps aux
What is the right thing to do to have a successful restart of services?
Is it even advisable to do something like this?
total used free shared buffers cached Mem: 596 573 23 0 8 71 -/+ buffers/cache: 493 103 Swap: 0 0 0